2
votes

I'm confused about whether Google Tag Manager is supposed to replace Google Analytics or work along side it.

I want to track page views and also send a user ID through to Google Analytics. If I add just the Google Tag Manager code below, will that register all of the usual Google Analytics pageviews, etc. or will it just send the userId through to Google Analytics?

If I add both the Tag Manager AND Google Analytics snippets below, will I get duplicate pageviews registered?

Sorry if this is a stupid question, but I've looked around for a definitive answer of whether you should use both snippets or just GTM but I can't find anything.

<!-- Google Tag Manager -->
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  'userId' : 'XXXXXXXXX' 
});

(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>
<!-- End Google Tag Manager -->


<!-- Google Analytics -->
<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-XXXXXXXX-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
1

1 Answers

3
votes

The GTM alone does nothing, you need to configure it. If you don't configure sending of pageview to Analytics obviously doesn't send it to Analytics.

There is a specific tag in GTM to send hits to Google Analytics and you can also send the userId through it. The GTM allows not to have codes on the page so all tracking is centralized, easier to manage and it is no longer necessary to modify the page code.