I mentioned on my last post that I was diving back into Google Tag Manager and the new interface was quite updated. I've been running into a few quirks that are worth mentioning when using a dataLayer.

There's a reason why I've always leaned toward 1 flat data layer per page where all data should be populated before triggering the tag manager. This makes for so many less headaches.

In my case of writing this post, the client was using the standard GTM dataLayer.push() functionality to define their data layer. However, instead of sending the data on every call, they would send it in bits and pieces. This caused some major headaches for a couple reasons:

  1. Triggers activate when their conditions are met. If a trigger activates, but you haven't defined all the necessary data, you might get a lot of empty values.
  2. Previous dataLayer pushes are stacked into the current call. This is good! However, you could potentially overwrite values. In my case, event was getting overwritten, so I didn't have the right trigger.
  3. Confusion for everybody. Building a data layer in multiple segments makes it awful for developers to try and find things later. It also makes it awful for whoever is setting up GTM since the data becomes fragmented.

How do we fix it?

That's the million dollar question... In this case, many of my rules depended on a certain event. I thought it was one event, but upon further inspecting the stack that GTM's debugger gives, it was actually another event that fired just slightly later. So fix #1 is to just update the triggers to reflect the appropriate event/call.

However, this may not be enough. So solution #2, though I don't like it, will be more accurate because of the stacking I mentioned above. If you add a rule to all your dependent tags to fire on Page Load, then the data will be more accurate. However, the page load event can be much later on some pages (I'm talking to you overly bloated news sites...), so you may miss the tracking if the user navigates away too fast.

Ultimate fix -- fix the data layer!! Build the data layer so it isn't going to be fragmented. Put ALL your data into one push call previous to the tag manager script and don't add any more pushes for like events. That means all page view data should be in ONE push and each user triggered event should be ONE additional push.