Detect if someone is blocking Google Analytics or Google Tag Manager

These days the use of adblocking tools is growing fast. These tools aren’t always used only blocking the ads, also analytics software is blocked sometimes.

Browser extensions like Ghostery and uBlock are used to get rid of all those trackers. Why wouldn’t a non-marketer disable all the found tracking software? With a couple of clicks someone has disabled 2000 trackers.

In this case Google Analytics and Google Tag Manager are disabled on marthijnhoiting.com. All the tags that should be loaded with GTM aren’t included anymore.

A user can have multiple reasons why he would do this. The problem is that our data gets more and more inaccurate. If 20% of our visitors is blocking Google Analytics we are missing 20% of the data we would like to have. Time to measure the percentage of our visitor that we can’t track anymore.

How to measure this?

After the page is loaded we are going to check if the Google stuff is loaded. Because i would track the GTM blockers as well we can’t use Google Tag Manager for this. So, we have to put our code in the source code of our website (the old school way). If we use GTM for this, the script isn’t loaded by visitors who are blocking Google Tag Manager.

JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<script&nbsp;type="text/javascript">

window.addEventListener('load',function()

{

if(window.ga&&ga.create)

{

console.log('Google Analytics is loaded');

}

else

{

console.log('Google Analytics is not loaded');

}

if(window.google_tag_manager)

{

console.log('Google Tag Manager is loaded');

}

else

{

console.log('Google Tag Manager is not loaded');

}

},false);

</script>

Put the script above on your website. Clear the cache and reload the page. Now we are going to check if everything is going well. We are doing this by writing the output to the console so we can check if everything is setup right.

JavaScript

1

console.log('Message');

Right click on your page, click on inspect element to open the console tab. In this example I am using Ghostery to enable and disable Google Analytics and Google Tag Manager.

When you disable Google Analytics you will get the following result:

When you disable Google Tag Manager and Google Analytics should be activated by GTM you will get the following result:

If everything is detected right we could measure it with Google Analytics. This sounds strange, but we could use the Measurement protocol to send our data.

The most easy way is loading an image pixel with javascript. But there are Browser extensions that prevent the source google-analytics.com from loading.

To show what is happening you have to replace the UA-XXXXXX-X with your own UA-code. The best practice is creating a new Google Analytics property, because the method described below will create a lot of duplicate (direct) traffic.

If we load this url and you have uBlock installed you will get a notice like this.

If you have installed uBlock allow this source and reload the page again. If you don’t have, you will see a white screen. But you can watch the impact of this call in Google Analytics under Real-Time -> Events. If you don’t see anything happen make sure you do not have filtered out your own IP!

N.b. This is also the way a lot of referral spam is generated. They are generating UA codes and calling these kind of urls.

The solution is using PHP. What we are doing is loading an server side generated image with javascript if we detect someone have disabled Google Analytics or Google Tag Manager. Our uBlock software doesn’t detect it as an tracker.

Upload this script to the root of your server and name it collect.php.

Oh sorry, that would be a nonsense since the server’s call is not tied to a visitor ID. So with this approach, we can see the ratio of (pageviews with GAor GTM blocked) / (pageviews with GAor GTM unblocked).
Still very useful info!

Hi Marthijn,
GREAT attempt!!!
Would/Could you share with us your findings?
Can you tell, what is the actual ratio for your website?
Is it about the 20%, you mentioned in your post?
If anybody else uses this method, I would be glad, if somebody could share this. I suspect, that it certainly depends a little bit on the kind of website, you manage

Har, Not if it’s in the terms-of-use on the site — if your site explicitly states it collects this data, the user has no right to sue – just the right not to visit your site (why terms-of use exist – to protect both parties). There is nothing illegal about gathering aggregate data to better your product – plus the funny thing is, most ad-blockers and track-blockers collect/track/report activity of their users – talk about irony!!

This approach gives me headaches. Because of several reasons (mostly financial) I have 1Mbit to use, with another bundled 1Mbit that doesn’t apply to http requests. Yes. That’s 1Mbit.

The problem is that it takes too long (according to the server and the ISP) to load things, and therefore I even get on both Windows, Debian and Mac (I don’t use adblock for some pages that I need) (I don’t even use Safari more than nessecary on the Macs neither Edge, but both of them get that annoying Please remove your adblocker).

I can understand that. Even though I want to use adblocking software on several sites. And, understand, that I mostly have 1Mbit.

When I have to click on something as “Like us on Twitter, G+, Facebook”, Whatever, if it takes too long a JS activates a closing curtain to the site I’m visiting. I blame this partly on both google and their programmers. Remember, not everybody has 1Gbit connections.

Very useful. I recently noticed a drop in traffic after I implemented GTM (before we used GA directly), I was puzzled at first but then I found out that GTM is more likely to be blocked by ads blocker than GA.

We have implemented a new tracking similar to what you suggest here. I would also like to add that if your GTM has tons of tags other than the GA you will not have those tags run when GTM is blocked. This is really bad if you put the livechat script inside the GTM tag for example. Beware of this issue.

In my opinion, the decision of ad blockers to block GTM is really bad, because we could have many useful things to run in GTM, not just ads and trackers.

Hi,
Great post!
I know you said this will increase the number the event hits and so I have set up another property as you suggested.

These event hits are being sent directly to the property without any filtering. So, does that mean that these hits are being triggered by Bots and other spammers visiting the website along with legitimate human users?

The site I have set up with this JS has very low traffic, is there a way to only send these event hits when real users arrive on the site instead?