Detecting if Google Analytics is being blocked using a Google Tag Manager Custom Template Tag

Last updated on November 7, 2019

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

8 Comments

  1. July 12, 2019
    Reply

    It’s a neat article/concept. One thing I noticed is that this page never seems to finish loading and now the console is up to 726 messages as I write.

    • July 12, 2019
      Reply

      Which messages do you mean?, the “WV: Sending data” ones?

    • July 12, 2019
      Reply

      it must be that one, it was the Yandex Metrica debug mode that i left enabled by default. It’s now fixed. Thanks.

  2. July 18, 2019
    Reply

    Sadly most privacy blockers like uBlock don’t only block analytics but the gtm too.

  3. Ruchita
    July 20, 2019
    Reply

    Getting error while importing the downloaded file from GitHub.
    Error is “File format is invalid. “.
    Please provide proper steps and file

  4. Bahadir
    July 23, 2019
    Reply

    What happens if Tag Manager is blocked?

  5. Oliver
    July 25, 2019
    Reply

    hey,

    unfortunately I get an error:
    missing ‘]’ at ‘,’
    Offending token ” at 26,3.

    Do you know how to fix that?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.