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”.

In one of my post I write pretty detail about Hotjar vs Google Analytics these day and how it affect to our website business deal.

In the detail post that I try hard to explain that, even I’m a premium subscribe from both of the analytic service ($142.40 a month included tax), I don’t find the real idea of them both for my Jekyll site since I used it for only work showcase and note writing.

And finally, after six months of using my Jekyll static site. I decided to remove all the scripts that are analytic and collect information on my sites.

I feel pretty OK and have had good moments since I made my decision.

I think both analytic systems that i mentioned in my post are suitable only for our commercial site or company website.

For personal websites, just like my website. It won’t make any sense or help me in any advance I could get. It is worse than you think on a personal website, low down the website, and count visits for only those who enable “javascript” the others who disabled javascript on their browsers will never show up on analytics.

Thanks for the interesting response - you are correct - this is not a “mission critical” facility that I desperately need - it is just useful to know how many hits the site is getting and to a lesser extent, what countries the hits are coming from . .

TLDR: Use server logs and Google Search Console.

1 Like

Just like @jhvanderschee mention above, you can easily use server logs to track all information you need about visitors. Or you can use Cloudflare Pages as well for counting traffic even a bot machine too.

This is how I add analytics on my Jekyll site, but only if I config.yml to enable it unless otherwise or false value, it will forever disappear.

{%- if site.google_analytics.enabled -%}
<!-- Google tag (gtag.js) -->
<script async src="{{ site.google_analytics.url }}{{ site.google_analytics.id }}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '{{ site.google_analytics.id }}');
</script>
  {%- endif -%}

Hmm . . this is what’s in the provided _includes/google-analytics.html:

<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
<script>
  window['ga-disable-{{ site.google_analytics }}'] = 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', '{{ site.google_analytics }}');
</script>

which is a bit different - should I just try your stuff?

Thanks!

It would help if you tried to following my step for a better development experience a long time value.

Or you can trust yourself by comparing both of the scripts added to your site and checking in a real life time to see how it different.

OK - I will give it a shot!

Thanks,
Phil.

You welcome Phil,

Another thing you should know is that,

  1. I Recommended disables javascript analytics.
  2. The people from Google that already contacted me about how to help them change the name of their product or change the phrase word on the analytics page so everyone could understand it easily.

And I already made it; I sent them a lot of information and a guide.

Google will make a massive change in the next few months. And that time, maybe we should talk about adding analytics late. But now it is a worse life ***.

1 Like

The doNotTrack API was an early attempt at providing better privacy on the web. It failed (replaced by ad-blockers) and is now deprecated, but some browsers still have the setting. The ga-disable code detects the doNotTrack setting, and presumably prevents Google from tracking the visitor. API Info:

2 Likes