diff --git a/docs/features.rst b/docs/features.rst index 609730d..1472859 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -78,6 +78,7 @@ providers send you can do it by setting the ``analytical_identity`` context variable in your view code: .. code-block:: python + context = RequestContext({'analytical_identity': user.uuid}) return some_template.render(context) @@ -89,6 +90,32 @@ or in the template: {% analytical_head_top %} {% endwith %} +or in context proessor: + +.. code-block:: python + + # FILE: myproject/context_processors.py + from django.conf import settings + + def get_identity(request): + return { + 'analytical_identity': 'some-value-here', + } + + # FILE: myproject/settings.py + TEMPLATES = [ + { + 'OPTIONS': { + 'context_processors': [ + 'myproject.context_processors.get_identity', + ], + }, + }, + ] + +That allows you as a developer to leave your view code untouched and +make sure that the variable is injected for all templates. + If you want to change the identity only for specific provider use the ``*_identity`` context variable, where ``*``-prefix is the module name of the specific provider. diff --git a/docs/services/google_analytics_gtag.rst b/docs/services/google_analytics_gtag.rst index c9ff31d..1a97cf5 100644 --- a/docs/services/google_analytics_gtag.rst +++ b/docs/services/google_analytics_gtag.rst @@ -94,22 +94,26 @@ Identifying authenticated users ------------------------------- The username of an authenticated user is passed to Google Analytics -automatically as the `user_id`. See :ref:`identifying-visitors`. +automatically as the ``user_id``. See :ref:`identifying-visitors`. -According to `Google Analytics conditions`_ you should avoid ... - -.. _`Google Analytics conditions`: https://developers.google.com/analytics/solutions/crm-integration#user_id -you should avoid sending Personally Identifiable Information. -Using `username` as `user_id` might not be the best option. +According to `Google Analytics conditions`_ you should avoid +sending Personally Identifiable Information. +Using ``username`` as ``user_id`` might not be the best option. To avoid that, you can change the identity -by setting `google_analytics_gtag_identity` (or `analytical_identity` to -affect all providers) context variable:: +by setting ``google_analytics_gtag_identity`` (or ``analytical_identity`` to +affect all providers) context variable: + +.. code-block:: python context = RequestContext({'google_analytics_gtag_identity': user.uuid}) return some_template.render(context) -or in the template:: +or in the template: + +.. code-block:: django {% with google_analytics_gtag_identity=request.user.uuid|default:None %} {% analytical_head_top %} {% endwith %} + +.. _`Google Analytics conditions`: https://developers.google.com/analytics/solutions/crm-integration#user_id