jazzband / django-analytical

Analytics services for Django projects
MIT License
1.2k stars 168 forks source link

Fixed gtag user_id setup and added support for custom dimensions #226

Open ericmassip opened 1 year ago

ericmassip commented 1 year ago

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 😊

ericmassip commented 1 year ago

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 commented 1 year ago

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 👍 😁