save-analytics-from-content-blockers: It won't work with Google Tag Manager

In your article Google Analytics is described. Google Tag Manager now replaces Google Analytics and is different. GTM first load a js file. That js file then loads “google-analytics.com/analytics.js”.

However, there’s no difrect link to “google-analytics.com/collect” in analytics.js anymore. Instead there’re different kinds of other links to:

Which ones should be proxied? Which ones not?

How to work with all that now?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 27 (15 by maintainers)

Most upvoted comments

Okay, I’ll double check.

I love you’ve started the issue from one question, and after a lengthy discussion it turns out to be a completely different question ♥ But we’re nailing it!

No. The way Global Site Tag works is different from GTM.

At the first glance, it is not different. Do not state that until you clearly understand the problem ^^

Go load the actual script at “https://www.googletagmanager.com/gtag/js?id=UA-NNNNNN-N” and check if that works the same way Google Tag Manager does. It won’t. And you’ll see what I’ve been talking about.

So I went and checked. Everything works just fine if we ignore SSL errors on localhost. Please remember to always describe what exactly doesn’t work for you, as it takes time to guess every time.

image

Note that on localhost there is no https set up, and, most likely, in your case the script fails because it requests analytics through the secure connection https://localhost/www.google-analytics.com/analytics.js (note https) which is not enabled in NodeJS proxy. Your proxy path-forwarding should handle https forwarding and request the NodeJS proxy via http only. To make it work on localhost, if it’s your case, you can cheat a little with the config file like this:

        specialContentReplace: { // Special regex rules for domains
            "www.googletagmanager.com": [
                {
                    regex: /https/g,
                    replace: "http"
                }
            ],
            "www.google-analytics.com": [
                {
                    regex: /https/g,
                    replace: "http"
                }
            ],

Please describe what exactly doesn’t work for you or was it your case. Hope this helps. Please, describe issues in very much detail, because it takes time to dig in and understand why you asking.