Search
  • Joseph Lowe

Beginner’s Guide to Google Tag Manager: Pushing Information to the Data Layer

Did the title intimidate you a bit? Thinking about the data layer within Google Tag Manager might feel like you’re jumping into the deep end of the pool without your floaties on, but I can assure you it’s not as frightening as you think. Keep in mind that the data layer is simply a filing cabinet for information that is interpreted by your website as actions are taken. These key and value pairs load each time a script loads on your site and store information needed for Google Tag Manager to run properly. Check out below for a few examples.



Now that might sound all nice and dandy, but you might be asking since Google Tag Manager is used primarily to build tags and track specific engagements throughout the site, how is a filing cabinet supposed to help in that endeavor? In this blog post, we’re going to review how to push specific data into the data layer, which can then be pushed into Google Analytics for proper tracking or reporting. I’d like to give a fair warning though, if you haven’t reviewed previous blogs or have a primary understanding of Google Tag Manager, check out some of our other content on Google Tag Manager.


As usual, before we start, I must give Chris Mercer from Measurement Marketing a quick shout out as I gleaned information from his course at CXL Institute, and his GTM courses go into even greater detail on the subject if you’re interested. Let’s get started!


Step 1: Defining what we need to track: Data layer pushes


First and foremost, every GTM user must know what it is they’re hoping to track. Just like within Google Analytics, GTM can become overwhelming if you don’t go into your container with a clear mission. For this post, I’m going to give us a hypothetical problem to work on that will take us through a few must-needed setup steps. Let’s say that your Chief Marketing Officer is interested in seeing how often individuals specifically engage with your newest blog on your blog page. In our case, that is our tracking page clicks & using timers blog. Perhaps your team spent money on an affiliate relationship to write the blog, and it’s important to understand performance overtime. She tasks you with tracking when people click on that blog specifically throughout the site (without accounting for clickthrough from email marketing or search engine page results). So where do we start?


Step 2: Creating javascript Custom HTML Tag


Once you’ve been given the directive, the first thing we have to do here is ensure that we can get the information we want to push into the data layer in the first place. That means we have to create a custom HTML tag using javascript. Don’t worry if you’re not a javascript pro yet. Just make sure follow the images below and ensure:


  • Each javascript script must start with <script> and end with </script>

  • When you type in the data layer within the script, it spells as dataLayer

  • Your key value pair matches ({‘key’: ‘value’ })



Those are the most common mistakes that I see as people start out with javascript for the first time. Our custom HTML tag above is going to push a character key to our data layer, so that we can identify when individuals click on our most recent blog. In this case, whenever the trigger is queued, character: Tracking Page Clicks will show up within our data layer. But, as we know, no tag can actually fire without a trigger.


Step 3: Create a trigger for the custom HTML tag




The next step here is creating a trigger that will only fire when the blog is clicked on. Since we’re tracking when the blog is clicked on the blog resources page, we have to think strategically as to where the blog might show up elsewhere and what unique identifiers can be used to track the clicks. For our website, there is no other place the blog might show, but it’s always important to think about the “what-ifs”. I used a simple identifier of the click URL containing a few words within the blog url we’re tracking. If you needed to track on a certain page, it might be a smart idea to further specify by using the click text contains specifier if your page there includes “read more” or “learn more”. With this trigger in place, we should now only see the tag fire once an individual clicks on that specific blog hyperlink on the blog resources page. Let’s click the blog and check to see if it worked out in preview mode.




Hooray! It looks like it worked out. Let’s point out a few key things here though. The first image above looks at the specific link click that triggered the tag. As we scroll all the way down the data layer for that script, we don’t see anything. Why’s that? It’s not supposed to update the data layer until the click itself happens and a message appears. The bottom image shows the message (which will be sent every time a data layer push is completed) and shows the character key showing as “Tracking Page Clicks” as we set up before. Keep in mind that the actual action that triggers a data layer push will not show the new data layer because the action must occur prior to the data layer push. The message will always show the data layer push that occurred if it was successful.


Step 4: Naming the GTM message for clarity


The last step in setting up a data layer push is naming the message that pulls through once the data layer is updated. For complicated GTM containers, the amount of messages and data layer pushes that can occur nearly simultaneously might become overwhelming. After all, who wants to go through 10 messages on their phone, nevertheless a data layer messaging system. Luckily, GTM users can specifically name each data layer push as they’d prefer.




All we have to do to ensure our message is named is add the key value pair of event and event name within our original custom HTML tag. Now each time that tag fires, we will see the name “Page Click Blog” as opposed to simply a message. This minor addition can truly help decipher what’s going on when GTM users look deeper into when tags are firing as well as setting up Google Analytics events from the data layer.


Pushing events from data layer to Google Analytics


Okay, pushing data into the data layer seems simple enough, but what about the tracking in Google Analytics? Let’s take this step by step.


Step 1: Create your custom data layer variable



The information that we’re pushing into the data layer is great to have, but remember that we need variables to transfer that information into Google Analytics. No variable means no Google Analytics data. All we have to do is build a user-defined variable called a data layer variable and type the key value we’re trying to track, which in this case is the character that we’ve been pushing into the data layer.


Step 2: Create a custom event trigger for “Page Click Blog”



Remember when we made the page click blog message show when testing tags? There was an ulterior motive for that classification. In order for us to build a Google Analytics event to fire and record data in Google Analytics, we have to have a trigger that fires each time that character information is pushed into the data layer. Well, luckily for us, we already created an event within our custom HTML javascript tag that fires each time the specific blog is clicked. That event (message) was called “Page Click Blog”. In this step, we create a trigger that fires whenever that specific event occurs that we made previously.


Step 3: Create a GA Universal Analytics Tag




In this step we can make a quick GA tag that creates a character category, shows we’re tracking blog choice and categorizes the label as the custom data layer variable we created earlier. We can simply attach the trigger we just created, so that whenever the data layer push occurs, a Google Analytics event will fire and record for us to see. Let’s see if it worked.




Boom! We can check our real-time reporting or quickly hop into preview mode of GTM to see that our new Google Analytics event tag is firing on all cylinders. Now, when your CMO reaches out to ask you how often individuals are clicking on your newest affiliate blog, you can easily check your events to see how often it’s occurring.


In the meantime, what Google Analytics events are you tracking on your website? What triggers are you using and how often are you using customer HTML tags? We’d love to hear how you’re optimizing your GTM account to better suit your business and clients.


This post was created in an effort to complete my CXL Institute Mindegree Scholarship obligation and speak to the materials reviewed in the course. The information is a combination of my previous knowledge and excellent insights from a phenomenal program.


5 views

Raleigh, NC

©2020 by Techucate LLC.