django-analytical icon indicating copy to clipboard operation
django-analytical copied to clipboard

Support for Google Analytics 4 tags

Open carlosnasillo opened this issue 4 years ago • 9 comments
trafficstars

Any new Google Analytics account is not able to create the previous 'universal' properties (UA-XXXXXX-Y, AW-XXXXXXXXXX, UA-XXXXXX-X, DC-XXXXXXXX) and instead now the tracking IDs look like (G-XXXXXXXXXX).

https://blog.google/products/marketingplatform/analytics/new_google_analytics https://support.google.com/analytics/answer/10089681

As a result Django-analytical does no longer support for any of the new google analytics integrations.

carlosnasillo avatar Dec 28 '20 19:12 carlosnasillo

Thanks, Carlos, for reporting this problem.

Can you suggest a specific change? Do you want to try a PR?

bittner avatar Dec 30 '20 10:12 bittner

Hi, I hope to solve this problem. but i am new to git contribution. can you help me to solve it?

likecodingloveproblems avatar Feb 11 '21 09:02 likecodingloveproblems

@likecodeingloveproblems It's good to hear that! Contributors are the best people around!

It's actually simple, as for the code change:

  1. You'd have to adjust the regular expression in templatetags/google_analytics_gtag.py, so that it allows the patterns @carlosnasillo listed above.
  2. And, of course, also align the related tests.

The test suite should then pass. Try running tox locally. It should all be green. Then you're ready to push your changes and open a pull request.

Mastering GitHub

If you've never made a contribution on GitHub (or GitLab or Bitbucket, and the like) there are a few things you need to learn, but the good news is there are also loads of nice tutorials that explain how to do it, e.g.

  • http://blog.davidecoppola.com/2016/11/howto-contribute-to-open-source-project-on-github/
  • https://www.dataschool.io/how-to-contribute-on-github/
  • https://guides.github.com/activities/forking/

Go forward, step by step! Come back here to ask for help if needed! :rocket: :+1: :100:

bittner avatar Feb 11 '21 14:02 bittner

thanks you are really kind

1.You'd have to adjust the regular expression in templatetags/google_analytics_gtag.py, so that it allows the patterns @carlosnasillo listed above. it is already adjusted to regular expression "^G-[a-zA-Z0-9]+$"

2.And, of course, also align the related tests. and all test by running tox passed

likecodingloveproblems avatar Feb 11 '21 19:02 likecodingloveproblems

@carlosnasillo Can you clarify your statement?

As a result Django-analytical does no longer support for any of the new google analytics integrations.

A G-XXXX... ID seems to be accepted by django-analytical, see PROPERTY_ID_RE in google_analytics_gtag.py.

bittner avatar Feb 13 '21 13:02 bittner

@bittner @likecodeingloveproblems

tldr: the issue might be with google_analytics_js.py instead of google_analytics_gtag.py

Back when I was updating my GA tag from G3 (ie. UA-XXXXXX-Y) to the new G4 (G-XXXXXXXXXX) it was not being parsed as correct when assigned to GOOGLE_ANALYTICS_JS_PROPERTY_ID in Django settings.py

See the PROPERTY_ID_RE within google_analytics_js.py

I hope this helps.

carlosnasillo avatar Feb 13 '21 20:02 carlosnasillo

Has this issue been resolved? I will like to contribute to this if it is still open.

theSekyi avatar Apr 05 '22 16:04 theSekyi

If I'm not mistaken this issue is still unsolved. Feel free to open a PR.

bittner avatar Apr 12 '22 13:04 bittner

Alright. I'll work on this

theSekyi avatar Apr 13 '22 07:04 theSekyi