Today I’m releasing a small Custom Template for Google Tag Manager that will take care of notifying the dataLayer about if Google Analytics is currently being blocked by the browser.
Some days ago, I published the following tweet, to get some user’s feedback on Twitter. The approach not really bad, but having to deal with code is not the best solution for most people.
I remember someone asking how to detect if GA was being blocked by user’s browser some weeks ago ( can’t remember who was, I’m sorry ), what about this approach using feach API?. anyone can bring up any handicaps about doing it this way? Gist > https://t.co/jLBRoBOVkM pic.twitter.com/zVvqMDJxGw
— David Vallejo (@thyng) July 8, 2019
I decided today to build a quick Custom Template to take care of checking if Google Analytics is being blocked. We’ll simply using the sendPixel library from Custom Templates. If you didn’t know if sendPixel library allows you to fire an onSuccess or onFailure callback functions.
Then based on these callbacks the template will be push the data accordinlty to the dataLayer. And from there you may do whatever your want, like notifying an external application with an event, or showing the user any alerts ( this was just a dummy idea, please don’t annoy the users on this ).
sendPixel(url, onSuccess, onFailure)
The Custom Template has some configurations available to fine-tune que current behaviour of the tracking.
- You can decide if sending an event if GA is being blocked or if GA is NOT being blocked
- You can individualy define the event names for each of the previous pushes
- You can set how often you want to the template to check if GA is being blocked. On each pageview, once per session ( 30 min ) or a personalized time period.
If you’re insterested on trying it, you can DOWNLOAD it from my github repo:
https://github.com/thyngster/gtmtemplates/tree/master/Google%20Analytics%20Block%20Checker
Leave a Reply