-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed gtag user_id setup and added support for custom dimensions #226
Open
ericmassip
wants to merge
4
commits into
jazzband:main
Choose a base branch
from
ericmassip:fix-gtag-user-id-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
232b242
Fixed user_id setup for gtag according to latest docs
ericmassip 5b85561
Added the possibility to include custom dimensions to be sent along w…
ericmassip 3784b09
Added custom dimensions section to the gtag docs
ericmassip ba99316
Added explicit python code blocks in the docs
ericmassip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,3 +117,52 @@ or in the template: | |
{% endwith %} | ||
|
||
.. _`Google Analytics conditions`: https://developers.google.com/analytics/solutions/crm-integration#user_id | ||
|
||
.. _google-analytics-custom-dimensions: | ||
|
||
Custom dimensions | ||
---------------- | ||
|
||
As described in the Google Analytics `custom dimensions`_ documentation | ||
page, you can define custom dimensions which are variables specific to your | ||
business needs. These variables can include both custom event parameters as | ||
well as customer user properties. Using the template context variable | ||
``google_analytics_custom_dimensions``, you can let the :ttag:`google_analytics_gtag` | ||
pass custom dimensions to Google Analytics automatically. The ``google_analytics_custom_dimensions`` | ||
variable must be set to a dictionary where the keys are the dimension names | ||
and the values are the dimension values. You can set the context variable in your | ||
view when you render a template containing the tracking code:: | ||
|
||
.. code-block:: python | ||
|
||
context = RequestContext({ | ||
'google_analytics_custom_dimensions': { | ||
'gender': 'female', | ||
'country': 'US', | ||
'user_properties': { | ||
'age': 25 | ||
} | ||
} | ||
}) | ||
return some_template.render(context) | ||
|
||
Note that the ``user_properties`` key is used to pass user properties to Google | ||
Analytics. It's not necessary to always use this key, but that'd be the way of | ||
sending user properties to Google Analytics automatically. | ||
|
||
You may want to set custom dimensions in a context processor that you add | ||
to the :data:`TEMPLATE_CONTEXT_PROCESSORS` list in :file:`settings.py`:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use an explicit code-block here (instead of .. code-block:: python There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added here |
||
|
||
.. code-block:: python | ||
|
||
def google_analytics_segment_language(request): | ||
try: | ||
return {'google_analytics_custom_dimensions': {'language': request.LANGUAGE_CODE}} | ||
except AttributeError: | ||
return {} | ||
|
||
Just remember that if you set the same context variable in the | ||
:class:`~django.template.context.RequestContext` constructor and in a | ||
context processor, the latter clobbers the former. | ||
|
||
.. _`custom dimensions`: https://support.google.com/analytics/answer/10075209 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use an explicit code-block here, as in the examples above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Added here