Foundation.mozilla.org: [Analytics] Install Google Tag Manager

Created on 7 Jan 2021  路  9Comments  路  Source: mozilla/foundation.mozilla.org

Describe the feature request

We need to:

  • Leave in place the existing GA tag
  • Create meta tags for each GTM property in the corresponding root template e.g.GTM-M3RMVLN
  • In JS: Fetch the content of the meta tag, if doesn't exist, return, load the GTM script
  • Separate dependencies on GA loading if necessary
  • Disable the page view event from GA
// Define gtmIdentifier here

    (function (w, d, s, l, i) {
      w[l] = w[l] || [];
      w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
      var f = d.getElementsByTagName(s)[0],
        j = d.createElement(s),
        dl = l != "dataLayer" ? "&l=" + l : "";
      j.async = true;
      j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
      f.parentNode.insertBefore(j, f);
    })(window, document, "script", "dataLayer", gtmIdentifier);

Property IDs:

  • [x] foundation.mozilla.org GTM-MD3XGZ4
    Note: Bug: Currently mozillafestival.org pageviews are being logged under this ID

  • [x] mozillafestival.org GTM-5TFTDCX

  • [x] mozillapulse.org GTM-KHLX47C

engineering

All 9 comments

Reminder: make sure iframe sources are whitelisted

@benhohner should we consider browser's do not track setting like what we do with Google Analytics tracking? https://github.com/mozilla/foundation.mozilla.org/blob/master/source/js/common/google-analytics.js

PR for adding GTM to MozFest is up (PR #5979). Once that's merged, I will file a PR on donate for the same work.

So the code we have on donate is pretty different than what we have on the Foundation site. We'll need to figure out how we wanna install GTM on donate (might end up needing different code).

@benhohner on donate, it seems like we massage the data before sending it over to GA. This is different than what we did on Foundation site so I hesitate to just "comment out" that code snippet and let GTM do the pageview tracking. Thoughts?

@mmmavis Thanks for flagging. Donate seems to have its own pretty complicated event system. It's probably best if we continue to add events in code for Donate.

So all we need now is to look into adding GTM to Pulse?

So all we need now is to look into adding GTM to Pulse?

Yup, I'm on it. Just need to get my dev env updated and have some dependabot PRs merged first.

@benhohner I've just landed the code on Pulse. Can you please verify it on GTM? I tried using the Tag Assistant to test but it kept saying it had issue connecting. Not sure if it's because I have DNT and a bunch of extensions installed. I'll try it on a different browser and see if it works.

Updates: ah CSP! Will ping you again after I whitelist those scripts.

@mmmavis works for me now!

Nice! I'm gonna mark this ticket closed :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xmatthewx picture xmatthewx  路  4Comments

alanmoo picture alanmoo  路  3Comments

hannahkane picture hannahkane  路  3Comments

kristinashu picture kristinashu  路  5Comments

kristinashu picture kristinashu  路  5Comments