I have Google Analytics code and Google Tage Manager code in the same page, when I use Google Tag Assisant extension to check my codes but it show that there is Google Analytics twice.
This is how I put it in head of my html page:
Google Analytics:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx"></script>
<script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-xxxxxxx');</script>
Google Tag Manager:
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-xxxxxxx');</script>
This is what Google Tag Assistant:
How I can fix this ?
If you have the GA tag in GTM, you do not need to have the GA script in the head.
Related
I'm using both gtag as well as GTM; how do I correctly include both of them in the ? Also, I was wondering if I should be overriding the dataLayer variable or checking if it already exists on every page -- i.e. dataLayer = []; or window.dataLayer = window.dataLayer || [];?
Does this look correct?
<!-- Google Tag Manager -->
<script>
window.dataLayer = window.dataLayer || [];
</script>
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- End Google Tag Manager -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UAXXXX"></script>
<script>
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXX');
</script>
This fully answers your concern: https://support.google.com/tagmanager/answer/7582054?hl=en
In short: remove your gtag completely and have all your tracking logic within GTM.
A tag manager is meant to house all your analytics logic and be the single point of access to anything behavioral tracking-related.
Regarding your DL question,
window.dataLayer = window.dataLayer || [];
is more adequate. Never redefine/overwrite the DL. Even when you believe it's not there. Async can be vicious, so be safe is always good in this case.
Oh, also GTM provides dataLayer automatically, so if you're moving your logic to it, you can as well skip defining it to leave the source cleaner. Or you can define it on the template level in case you want to be able to push into it before GTM is loaded.
The website www.3dz.it is using with WordPress.
There are four languages and each one on a different domain (Italian .it, France .fr, etc.). It is in this way using WPML with the multi-domain option, since April 2018.
Up to April 2018, the events monitoring was going. For three months with the four domains, we were without data; in July we add the new analytics code so each language has an own Analytics property.
But we are still without the monitoring of the events.
Google analytics tracking code is since July 2018 set how is actually online.
<?php if(ICL_LANGUAGE_CODE=='en'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-4');
</script>
<?php } elseif(ICL_LANGUAGE_CODE=='it'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-1');
</script>
<?php } elseif(ICL_LANGUAGE_CODE=='es'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-3');
</script>
<?php } elseif(ICL_LANGUAGE_CODE=='fr'){?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-77106642-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-77106642-5');
</script>
<?php } ?>
Someone can tell me please how to implement the code to obtain the monitoring of the events again?
Maybe you could try to add the tracking codes on the website using Google Tag Manager? It's very easy to add multiple tracking codes into your Google Tag Manager account and only place one GTM-code to your website.
The developer notes are pretty straightforward with regarding adding event tracking to the page, for the gtag version of GA. However, I would also agree that managing your GA set-up and event tracking via Google Tag Manager would be more appropriate and scalable for your situation.
The problem was the different library of Analytics. I solved it calling google assistance. I changed the event script in the website and I modified the conversion in Analytics (event categories and actions)
I want to be able to capture the full URL on a single page application SPA and that includes the hashtag. My GA tracking code is below. It’s capturing the full URL including the #index for the home page but when I click on the About button for example the URL that gets sent to GA doesn’t change. The url should now end with #about. The tracking code is below. How do I fix this so that when they click the other buttons the URL changes.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-XX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-XX', {'page_path': location.pathname + location.hash});
</script>
You need to add the following to your routing:
gtag('event', 'page_view',{'page_path': location.pathname + location.hash});
While I see some numbers on the "Real-Time overview" page, I don't see the pageviews / sessions data in "Audience overview" on my website. I'm having a hard times understanding why.
The website is: https://everyelixirvideo.page/. It's a single-page website with no custom javascript. This is the current tracking code:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-33420511-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-33420511-4');
gtag('config', 'UA-33420511-4', {'page_path': "/"});
</script>
What am I missing?
Here are the screenshot of "Real-Time overview" and "Audience overview" pages:
good:
not good:
I used to be able to use two different Google Analytics accounts on a single page with the old ga.js.
This is how I used to do it:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22766576-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setAccount', 'UA-OTHER-ID-1']);
_gaq.push(['_trackPageview']);
...
Google Analytics now defaults to use tag manager's gtag.js and looks like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-74053665-19"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-74053665-19');
</script>
The UA id is embeded in the JS call as well as in the config. It doesn't look like it's possible to fire two visits for two separate accounts anymore. Does anyone have any other solutions?