#GTMTips: Fix Missing Page View Event and Disabled Triggers – News Couple
ANALYTICS

#GTMTips: Fix Missing Page View Event and Disabled Triggers


Google Tag Manager should be relatively easy to implement. Just paste the container snippet into a file <head> of the page and you are good to go! However, at some point, you’ll want to create a file dataLayer structure, too (read more about dataLayer Here). There are two ways to do this: the right way and the wrong way.

In this article, we’ll see what happens if you do it the wrong way, how to identify the problem, and how to fix it.


X


Simmer . Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava right in your inbox!

Tip 71: Missing page rendering event, GTM players not working?

if you open preview situation on your site, look at the list of events in the right navigation bar, you should Always Review the following three hypothetical events for GTM:

  1. page width – This is the event he was pushed into dataLayer In the Google Tag Manager container snippet (event name is gtm.js).

  2. DOM ready – This is the event he was pushed into dataLayer Once the HTML page is viewed by the browser (the event name is gtm.dom).

  3. Loaded window – This is the event he was pushed into dataLayer Once the page load and all associated resources, execution and rendering are complete (the event name is gtm.load).

You should always see (2) and (3) – there is very little you can do to spoil them. But you may not see a file page width Event. If you don’t, that means you are messed up dataLayer Application.

Google Tag Manager creates a file dataLayer build alone .push() In the JavaScript library that represents your container. The gtm.js Event pushed to dataLayer in the container snippet, and it is used to trigger any tags that use page rendering or all pages triggers.

The main reason for not seeing page width The events are simple. you have overwrite dataLayer Modified in the container snippet with a brand new array. Do it as follows:

  <!-- Google Tag Manager container snippet here -->
  (function...)
  <!-- Google Tag Manager container snippet ends -->
</head>
<body>
  <script>
    var dataLayer = [
      someVariable: 'someValue'
    ];
  </script>

See the problem? using grammar var dataLayer = ..., you are resetting a file dataLayer variable to a new array, thus overwriting whatever was in it before (such as the Google Tag Manager’s listener). since writing dataLayer, it no longer works properly with GTM, the usual show is that GTM players don’t work anymore, As for. So if you have a Click / All Elements launcher on the site and nothing is pushed to it dataLayer When you click around, you’ve probably overwritten GTM Tools dataLayer with your reformatting.

How do you fix it? basic. Always check for dataLayer Before adding items to it, and always add items to it dataLayer Only with push() Command.

// WRONG! NEVER USE THIS:
var dataLayer = [
  pageType: 'home'
];

// CORRECT! ALWAYS USE THIS:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(
  pageType: 'home'
);

This is a popular topic on this blog and many others just because it’s so easy to screw up. It does not help that somewhere in the documentation for GTM there are still instructions for use declarative Setting method dataLayer.

Are there any other typical Google Tag Manager bugs that you can think of, that have been around for a long time, and are likely to appear for a long time to come?



Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button