Google Analytics is getting harder to use - latest site "ga-disable . . window.doNotTrack"

People,

In the old days, with only infrequent use of GA for a new, low-traffic Jekyll site, I found it reasonaby straightforward to set up GA with the “UA-” identifier - now I am stuck trying to use the new “G-” tag method. When I use the browser developer mode to look what is inside the home page I see:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-RBF29Y82G0"></script>
<script>
  window['ga-disable-G-RBF29Y82G0'] = window.doNotTrack === "1" || navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1";
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-RBF29Y82G0');
</script>

What is this stuff about “ga-disable . . window.doNotTrack” etc?

I have put the tag in _config.yml of a fork of the “Minima is a one-size-fits-all Jekyll theme”.

It fairly obviously turns off the google analytics if DoNotTrack is set,

But what does this have to do with GitLab?

1 Like

Are you setting the window options with ga-disable? When I’ve put in on static HTML sites (standard html+css+js without an SSG), then I just add:

<script defer src="https://www.googletagmanager.com/gtag/js?id=G-TAGxxxxxx"></script>

I never had to add any more than this (unless something has changed that I don’t know about). If you didn’t put it, then is the SSG (Jekyll) generating this code? Or do you only see this after it has been deployed to Gitlab Pages (I assume you are using this?). Another alternative, would perhaps be to generate/build the static code locally on your machine, and see if it appears to figure out where the code is coming from if it’s Jekyll or Gitlab Pages, for example. You could also always publish it free to Netlify and then compare if it’s the same as well if building locally isn’t an option.

Thanks for responding!

Yes, it was - I deleted the line and made a bit more progress but I still find that GA has become unnecessarily complex for my use cases so I have now been looking at alternatives and GoatCounter seems more like what is appropriate for me . .