You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 14, 2024. It is now read-only.
So what I read from this code, a callback function needs to be added to the dataLayer array. It seems like this callback function is supposed to be called from GA at some time.
The problem is, that function is never called. And I cannot find any references on the web that mention adding a function to that array. Everybody just puts objects in there, with keys and some values.
So none of my script runs in the first place. Can you please explain how this thing starts? I'm only interested in Google Analytics with analytics.js, nothing else.
Here's my code:
window.dataLayer=window.dataLayer||[];functionremoveUtmParams(){console.log("removeUtmParams called");// Only do this if the browser supports changing the URL of the pageif(window.history.replaceState){// Wait for the analytics library to be loaded, or the timeoutletretries=200;letpollInterval;pollInterval=setInterval(function(){if(retries--<0||window[window.GoogleAnalyticsObject]){clearInterval(pollInterval);// Then push a function onto its queueconsole.log("polling completed, retries:",retries);window[window.GoogleAnalyticsObject](function(){console.log("cleaning URL");// Now the tracking is done, clean up the URLletcleanSearch=window.location.search.replace(/utm_[^&]+&?/g,"").replace(/&$/,"").replace(/^\?$/,"");letcleanUrl=window.location.pathname+cleanSearch+window.location.hash;window.history.replaceState(window.history.state,"",cleanUrl);});}},50);}}functiongtag(){dataLayer.push(arguments);}gtag("js",newDate());gtag("config","UA-.....",{"anonymize_ip": true});console.log("pushing to dataLayer");gtag(removeUtmParams);
The log says "pushing to dataLayer" and nothing else. The URL is untouched. The page view is tracked in the realtime view.
PS: When I call removeUtmParams directly instead of adding it to the array, it runs to completion, cleans the URL, but I can't see the source value in the realtime reports. But then again, I can't even see the source in the report when I don't clean up the URL. Strange.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
So what I read from this code, a callback function needs to be added to the
dataLayer
array. It seems like this callback function is supposed to be called from GA at some time.The problem is, that function is never called. And I cannot find any references on the web that mention adding a function to that array. Everybody just puts objects in there, with keys and some values.
So none of my script runs in the first place. Can you please explain how this thing starts? I'm only interested in Google Analytics with analytics.js, nothing else.
Here's my code:
The log says "pushing to dataLayer" and nothing else. The URL is untouched. The page view is tracked in the realtime view.
PS: When I call
removeUtmParams
directly instead of adding it to the array, it runs to completion, cleans the URL, but I can't see the source value in the realtime reports. But then again, I can't even see the source in the report when I don't clean up the URL. Strange.The text was updated successfully, but these errors were encountered: