Google Tag Manager 'Page View' tags not firing
If you landed on this page, you are probably trying to figure out why your ‘Page View’ tags aren’t firing. I ran across this problem myself, and that is why I am writing this blog post.
First up, make sure your Google Tag Manager is added to your site. This sounds dumb, but it is the first step we have to take. You should find code like below inside the <head> </head> tags of your website.
<!-- 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-MYGTMCODE');</script>
<!-- End Google Tag Manager -->
Now this is a basic setup. As long as that code is in there you should be good. Next, the question is, are you using the data layer? If you are, you of course added the following snippet of code like the examples show.
<script>
dataLayer = [];
</script>
Now here is where the magic broke or happens. You may have skimmed over it, but that code needs to be ABOVE your Google Tag Manager code. I found that if it is below it, it will break the events and not fire correctly.
A correct implementation looks like the following. Make sure to update the tracking ID (this page example is: GTM-MYGTMCODE with your actual tracking ID.
<script>
dataLayer = [];
</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-MYGTMCODE');</script>
<!-- End Google Tag Manager -->
I place this code as high in the <head></head> tags as I can. Hopefully this solved your problem of the Page View event not firing when it should have.