Chapter 7 of 12:

Well, it’s official…earlier this week I finished up my CXL Digital Analytics mini-degree course work! I am a certified, bonafide, sanctified Digital Analyst. Okay, maybe not sanctified, but fortified, perhaps? In many ways, I suppose. Edified? Absolutely.

So, now that I’m basically a pro, I’m going to go forth and share my newly acquired wisdom with one and all…well, all that care to learn about the Dark Arts that is Digital Analytics. Whoa! Dark Arts’ initials are D.A., and Digital Analytics’ initials are also D.A…. Coincidence? I think not. Well, I suppose the same could be said about Dumbledor’s Army…so I suppose it depends on if you want to choose to go down the path of righteousness, or be cool like me and choose to go down the path that ROCKS! (Mad kudos and my profound respect to you if you managed to get the movie reference there.) As for me and my house, we will choose the path that rocks where Digital Analytics = Dark Arts. The line in the sand has been drawn. The gauntlet has been thrown. Choose wisely…

Ahem, well, uhh..(clears throat uncomfortably)… that, uhh.. that paragraph really got away from me there, didn’t it? Sorry ‘bout that.

Getting back to that sharing of wisdom, today I want to do explore and hopefully help demystify the abstract concept of the Google Tag Manager data layer.

So, what exactly is a data layer? Well, there are quite a few ways of explaining it depending on your comfort level with technical speak.

For those of you that would prefer the simplest, most accessible explanation of the data layer:

  • The data layer is a kind of digital safe house that exists at the top of a web document where lonely event data that is created when a user interacts with elements on your webpage(s) can go to for shelter and then accessed when needed to be sent where it needs to go to be the best, most productive data it can be.

For the more technical person that prefers the most definitively accurate explanation (paraphrasing Google’s explanation):

  • A data layer is a javascript object that collects data in a standardized way, which is composed of key/value pairs. Wherein, a “key” is a categorical, classification of a thing or things, and the “value” is the corresponding thing that the key categorizes. (e.g., key: “Author”, value: ”J.R.R. Tolkien”)

One thing that is super important to understand about the data layer is that without it, Google Tag Manager can’t and won’t function properly, but! it’s also one of the coolest, most powerful aspects of Google Tag Manager. The reason being, website documents are being changed, modified, or optimized on a fairly regular basis. Were you to try and collect event data with inline javascript, and that element is fundamentally changed, you are faced with the challenge of re-establishing event tracking each time a change occurs. The solution that the data layer provides for this particular problem is that once created, it exists and lives within the <head> portion of the web document, which fortunately experiences significantly fewer changes throughout the page optimization process than say the <body> section of the document leaving your data tracking and collection efforts perpetually intact.

Now, I’m sure at this point you’re completely sold on utilizing the data layer in all of your Tag Manager guided adventures, so let me show you how to go about accessing and sending data to the data layer. So this is how the GTM developers guide instructs on how to create the data layer:

As I mentioned in the more technical explanation, this code creates an empty javascript object “[ ]” or digital container that is used to hold the event data that you push to it. Now that your data layer has been created, let’s send or push some event data to it. Let’s say you’re setting up some eCommerce event tracking for an online bookstore, where a user makes a book selection. You would capture and send that event data in a format that might look something like this:

Let’s break this down step-by-step quickly:

First, you would create this tag, but selecting a custom HTML tag from the GTM tag template list. I like to clear any existing template code out and start by adding an opening <script> and closing </script> tag:

Next, type out the recommended dataLayer.push protocol that tells the script what to do:

As a better tag management practice, I recommend (CXL also recommends this) adding an “event” to categorize the specific data that is being pushed as the code executes:

And then, following the event, you can add any additional contextual data, within the key/value format, about the event to a level of granularity that you or your team are comfortable with (Personally, I prefer as much context as possible to avoid misunderstanding and data ambiguity):

NOTE: Be sure to strictly follow the syntax laid out here to avoid the headache of having to go debug your tag over and over.

  • Next, you will want to configure the trigger to fire when this click event takes place using any of the auto-event click variables that work best for you.
  • Once you have named your tag, save it and proceed to (as Chris Mercer likes to say) “Trust But Verify” by Previewing and making sure it’s working as you intended.
  • Once you have confirmed the tag’s functionality, publish the tag and you will be in business. That’s it!

Okay, so now that you have that data up in the data layer, how do you access it? That’s probably something that would be valuable to know, right?

(Enter GTM Data Layer Variable)

This little ditty makes collecting data from the data layer a cinch! Simply navigate to the variables section and click “New” in the User-Defined variables section, a side window will pop open and from there you select the “Data Layer Variable” (DLV) option. Once selected, all you will need to do is type the name (this is case-sensitive, so type it exactly as you did in your dataLayer.push() tag) of the “Key” of the value you are wanting to retrieve from the data layer, like so:

This specific DLV will return the value of “J.R.R. Tolkien”, which is exactly what I want. Additional DLVs can be created to capture and return the “Book Series Name”, “Book Series Order”, and “Book Title” values. From here you can send this information to Google Analytics or any other 3rd party platforms you use to add a beautiful layer of contextual clarity to the data you’re actively collecting.

Pretty neat, huh?

Just a nomadic digital analyst finding his way to great light and knowledge through sharing it with you!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store