#GTMTips: Why does the Google Analytics flag show “Failure” – News Couple
ANALYTICS

#GTMTips: Why does the Google Analytics flag show “Failure”


I covered the most common issue with tags not being activated in Google Tag Manager in my article about the status ‘still running’. However, there is an additional issue you may encounter with Google Analytics: tags that display status Failed, which refuses to send any data to Google Analytics.

There are several possible reasons for this, and we will explore them in this article.

Note that Which It can indicate the tag type in Google Tag Manager Failed. With the advent of custom templates, more and more templates are becoming do it right, which means that it is explicitly inferred Failed The situation when the tag encounters problems. This is not the case with many original templates – they eat errors and refuse to indicate that something is wrong.


X


Simmer . Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava right in your inbox!

There are two reasons (I can think of) this behavior appears.

Reason 1: the analytics.js library is blocked

If your browser is blocking The analytics.js library, which means the client is unable to load it from https://www.google-analytics.com/analytics.js, the tag will point to a file Failed Status.

This could be due to browser extensions like Ghostery or uBlock Origin, or it could be a firewall setup in your network. can even be the browser itself (Firefox in a private window, for example).

analytics.js has been blocked

The easiest way to check if this is the cause is to open a file network tab of your browser’s developer tools, and search for analytics.js. If it is blocked, it should not appear at all, or should appear with a clear indicator. In some browsers, you will see messages about resource blocking in the browser console.

Firefox Console

The image above is from Firefox.

Noticeable! If the analytics.js library can load, but the extension or browser blocks calls to a file www.google-analytics.com/collect End point, will tag Not Signal Failed Status.

Reason 2: The namespace is busy

When the Google Analytics library is loaded, it tries to create a file global way the name of the thing ga (by default). The name of this method can be changed in the analytics.js snippet as well as in Google Tag Manager (see below).

However, if this global variable is already used, Google Analytics fails to initialize and the flag state is set to Failed.

An easy way to check this is to run the following command in the JavaScript console:

console.log(window[window['GoogleAnalyticsObject']]);

the answer Should It looks something like this:

Content of the analytics.js . method

However, they are minified and can change, so it’s not a robust way to check them. Alternatively, you can also try this:

console.log(window[window['GoogleAnalyticsObject']].loaded);

If you get undefined, it means that Google Analytics has Not Loader, and something else that occupies the namespace.

It is very difficult to correct this error if some other JavaScript is already overwriting the GA namespace. You can try searching for it in your browser’s developer tools sources, or you can try blocking scripts one by one until you find the one causing the conflict.

Sometimes that’s not the case JavaScript which replaces the object. Browsers have an unconventional way to customize HTML elements for the world window variable too, as long as they have a file id attributed.

In other words, if the page contains an HTML element whose ID is the same as the name of the Google Analytics object (ga By default), the tag will also indicate Failed Status! An easy way to check is to run the following code in the JavaScript console:

console.log(document.querySelector('#' + window.GoogleAnalyticsObject));

If this returns an HTML element, then you have this exact problem.

GA is found in span

Fix it!

So, what is the fix?

Well, you can walk around the site, and look for the JavaScript that is causing the problems, or you can simply Rename the public method using Google Tag Manager. By renaming the method, you protect the variable from further conflicts.

You just have to do it Once, so it doesn’t matter if it’s in the Google Analytics settings variable or in the settings of an individual tag. You are Act Want to make sure that the change in first The tag that is activated on the page, so make the change in everyone Your tags are a good precaution.

You can find the setting by expanding advanced configuration From the Universal Analytics tags (or the Google Analytics settings variant).

Write a new value in a file public office name domain, make sure This is amazing The variable is not reserved (for example, run console.log(window['yourNewVariableName']) in the JavaScript console). I usually choose something like _ga or __ga.

Change the name of the public office

Once you make this change, your tags should start working fine.

summary

It’s an extreme case, but when it hits you, it can be very difficult to correct.

Scripts that grab global variables are one of the main reasons you should do it Always avoid polluting the global namespace when writing JavaScript.

However, when there is He is conflict, you are usually left with two options:

  1. Find the conflicting script or HTML element, and fix it.

  2. Accept defeat and modify the settings of the Universal Analytics tag that is active on the page.

Both have their drawbacks. sometimes you I can not Changing the conflicting script, because the script does not have the ability to support changes in the global namespace. And sometimes changing the method name in your tags can cause problems when trying to figure out why first-party and third-party scripts that depend on the default method name are supported (ga) Suddenly stopped working.

The important thing is to know how to correct the problem and sort it out. We hope this article provides some guidance on how to do this.



Source link

Related Articles

Leave a Reply

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

Back to top button