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

feat(google-analytics): migrate to gtag.js with dual tagging #10687

Merged
merged 11 commits into from
Mar 20, 2024

Conversation

caugner
Copy link
Contributor

@caugner caugner commented Mar 13, 2024

Summary

(MP-951)

Problem

We have been using analytics.js, which is being deprecated (see here), and we want to smoothly transition from UA to GA4 using dual tagging (see here).

Solution

Migrate to gtag.js, and support multiple measurement ids.


How did you test this change?

Kicked off a stage deployment.

Ran BUILD_GOOGLE_ANALYTICS_MEASUREMENT_ID=foo,bar yarn tool google-analytics-code and manually checked the result in client/build/static/js/gtag.js:

// ...
if (Mozilla && !Mozilla.dntEnabled()) {
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'foo', { 'anonymize_ip': true });
  gtag('config', 'bar', { 'anonymize_ip': true });

  var gaScript = document.createElement('script');
  gaScript.async = true;
  gaScript.src = 'https://www.googletagmanager.com/gtag/js?id=foo';
  document.head.appendChild(gaScript);
}

Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions github-actions bot added merge conflicts 🚧 Please rebase onto or merge the latest main. and removed merge conflicts 🚧 Please rebase onto or merge the latest main. labels Mar 15, 2024
@caugner caugner changed the title feat(google-analytics): migrate to gtag.js feat(google-analytics): migrate to gtag.js with dual tagging Mar 18, 2024
@caugner caugner marked this pull request as ready for review March 18, 2024 18:45
@caugner
Copy link
Contributor Author

caugner commented Mar 19, 2024

FWIW Dual tagging looks fine on stage: https://developer.allizom.org/static/js/gtag.js

@@ -123,7 +123,7 @@ test("content built foo page", () => {

// The HTML should contain the Google Analytics snippet.
// The ID should match what's set in `.env.testing`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ID actually being checked?

Copy link
Contributor

@argl argl left a comment

Choose a reason for hiding this comment

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

Looks fine, just one tiny comment/question

@caugner caugner merged commit 56dbe78 into main Mar 20, 2024
16 checks passed
@caugner caugner deleted the migrate-to-gtag branch March 20, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants