Add the missing get_identity prefix to google_analytics_gtag, test it (#217)

This commit is contained in:
Petr Dlouhý 2022-07-19 08:58:28 +02:00 committed by GitHub
parent 858a05307b
commit 2163c77684
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -57,7 +57,7 @@ class GoogleAnalyticsGTagNode(Node):
def render(self, context):
other_fields = {}
identity = get_identity(context)
identity = get_identity(context, 'google_analytics_gtag')
if identity is not None:
other_fields['user_id'] = identity

View file

@ -59,6 +59,28 @@ class GoogleAnalyticsTagTestCase(TagTestCase):
r = GoogleAnalyticsGTagNode().render(Context({'user': User(username='test')}))
assert "gtag('set', {'user_id': 'test'});" in r
def test_identity_context_specific_provider(self):
"""
The user_id variable must be set according to
google_analytics_gtag_identity variable in the context.
"""
r = GoogleAnalyticsGTagNode().render(Context({
'google_analytics_gtag_identity': 'foo_gtag_identity',
'analytical_identity': 'bar_analytical_identity',
'user': User(username='test'),
}))
assert "gtag('set', {'user_id': 'foo_gtag_identity'});" in r
def test_identity_context_general(self):
"""
The user_id variable must be set according to analytical_identity variable in the context.
"""
r = GoogleAnalyticsGTagNode().render(Context({
'analytical_identity': 'bar_analytical_identity',
'user': User(username='test'),
}))
assert "gtag('set', {'user_id': 'bar_analytical_identity'});" in r
@override_settings(GOOGLE_ANALYTICS_GTAG_PROPERTY_ID='G-12345678')
def test_tag_with_measurement_id(self):
r = self.render_tag('google_analytics_gtag', 'google_analytics_gtag')