Reputation: 1187
Is it possible that my GTM code is failing because of some conflict with Google Analytics and an HTML element I have with <input id="ga" name="ga">
?
My tag for Google Analytics is:
<style>.async-hide { opacity: 0 !important} </style>
<script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-XXXXXXXXXXXXX':true});</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXXXXXX', 'auto');
ga('send', 'pageview');
</script>
Should I change the 'ga'
to something else and it'd still work but without the conflicts?
I found this answer but I'm not sure if it's the same issue, however I'll try to do it (the reason why I don't try and test it by myself is because it will take a lot of time until the marketing team can check it).
Changing the Global GA Object in google tag manager
Upvotes: 1
Views: 776
Reputation: 1187
As the answer by Michele Pisani says, it does conflict, and it can be solved with this answer (changing the global function name):
Changing the Global GA Object in google tag manager
Upvotes: 0
Reputation: 14199
Yes, it is certainly a cause.
The error it will generate is:
Uncaught TypeError: ga is not a function
You can see it in this JSFiddle (see error in console).
Upvotes: 1