Skip to content
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
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ericmassip
Copy link

@ericmassip ericmassip commented May 1, 2023

Fixes #124
Fixes #197
Fixes #225

The correct way to send the user_id using the gtag has changed according to the docs. I have applied the required changes to the code to comply with the new specification via gtag('config', ...) as opposed to gtag('set', ...).

In addition, I decided to take the chance to add support for sending custom dimensions in GA4. Note that the custom dimensions are appended to the gtag('config', ...) command as a json serialized dictionary. There are (at least) two ways of adding custom dimensions that are sent along with every event with gtag. One is by using the set command and the other one is by using the config command. IMO, the latter is more convenient because you can add the user_id to the rest of dimensions and send it all together in the same command, so that's how I did it, but I'm happy to be convinced otherwise 😊

Copy link
Member

@bittner bittner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the tests fail for an infrastructure issue.

If you dare to fix it, it's ubuntu-latest that needs to be replaced by ubuntu-20.04 in the GHA tests workflow. This is necessary, because Python 3.6 is not available anymore in the former VM image.

I don't want to ask too much, but if you really care you may want to open a separate PR to make the tests run against Django 4.2 (dropping 4.0) and Python 3.11 (in addition), and fix the pipeline issue there. That would be optimal.

References

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::
Copy link
Member

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.

.. code-block:: python

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Added here

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`::
Copy link
Member

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 (instead of ::), as in the examples above.

.. code-block:: python

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here

@ericmassip
Copy link
Author

I don't want to ask too much, but if you really care you may want to open a separate PR to make the tests run against Django 4.2 (dropping 4.0) and Python 3.11 (in addition), and fix the pipeline issue there. That would be optimal.

@bittner Sure! I can fix the pipeline and update the Python and Django versions. I might need a few days to find the time but I'll do it 👍

@ericmassip
Copy link
Author

Sure! I can fix the pipeline and update the Python and Django versions. I might need a few days to find the time but I'll do it

I see the CI updates are already being taken care of in #227 👍 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants