How To Leverage Variables in Google Tag Manager
Four scenarios on how variables can make your life easier when tagging your site – widen the amount of data your collecting while reducing time and effort.
You’ve learned the seven types of triggers that you can associate to your tags to really broaden the type of event data they can send to Google analytics to help in your analysis. Now let’s take a look at variables and how variables can do the same thing. Variables can help widen the amount of data that you’re collecting, but also in a way that reduces the amount of time and effort it takes in having to add hundreds of tags to your Google Tag Manager account. I’m going to show four different scenarios on how variables can help make your life easier when tagging your site, plus you’ll get one bonus way they can apply a variable to a trigger to accomplish something similar as well.
All right, so let’s take a look at Macy’s here. Picture this: You roll out a new site, you have a new menu and you and the team are wondering what are people clicking on? What are people not clicking on? What are people clicking on that’s driving conversion through your menu? How does it work on mobile versus desktop? Well, by using a variable that you can assign to your event, all you need to do is create one tag with one trigger and you’ll automatically collect all of these different categories and subcategories without having to go through and create thousands of tags, in Macy’s case, that tracks the click of each one of these elements. Let’s take a look at how that works.
Inside of Google Tag Manager here, you’ll see I have an event. It’s a main navigation click event. It’s our standard event type that you’ve seen throughout these videos. The only change here is where we have our main nav click. Main nav click as our event action. We’re assigning the Click Text variable. It’s inside of Google Tag Manager. They have a plethora of built-in variables like Click Text, Click URL, Page URL, et cetera, that you can apply to all of your tags inside of Google Tag Manager. Not only that, any custom variables that you’ve created inside your account, like product name, variant name, inventory, which we’ll look at shortly, those can also be applied to tags.
In this example, I have one tag, one trigger and we’ll see how this works for this test site. So I’ll go ahead and click on these two navigation items and we see my two click events here. Event number one, we can see main nav click, softball bats, and now let’s look at our second one, main nav click, baseball bats, and you can even track that all the way back to your Google Analytics realtime report while you’re testing. You can see these are the event actions that I just triggered. So again, super simple. Main nav click, make sure you have the right trigger, add a Click Text, and this turns one single action into potentially hundreds of different variations where you can sort rank conversion rates, revenue, et cetera based on usage.
Scenario number two. You’re on a homepage, you have banners, promos, call-outs, whatever it might be, and you don’t want to necessarily have to track and create an event for every single banner or call-out that you have. In this example, I have a section here with three category call-outs. I have one event, one trigger, and since this changes out quite a bit and it’s an image in addition to text, I want to track the Click URL. So basically the destination that someone’s going to go. So let’s just look at this. Two clicks. We’ll go back to Google Tag Manager. We’ll take a look at the featured product click and we can see featured product click with our Click URL variable assigned to the end, and we can see the category page, featured product click, and now we can see the URL was automatically appended to the end of the event action and we can see this one also triggered and we’re good. So that’s example number two.
Example number three. Many of you, you might have enhanced eCommerce reporting. Hopefully you have an enhanced eCommerce reporting set up on your store. Every time someone’s loading a product view on your store, you’re sending an event to Google Analytics, reviewing a product, adding the product, et cetera. You’re setting that through an event action. So this case, we have our product detail view event that triggered, and this ultimately sent an enhanced eCommerce event in addition to, I have another tag here for Klaviyo as an example.
In this example, if we go back to Google Tag Manager and we’ll look at our product detail view, here we have the product detail view event and the variable that I’ve assigned to here is actually a product view variance. So I’m attaching… This is a custom variable that’s in the store and it’s the variant for this product. So now when I am firing this event, sending it to Google Tag Manager and ultimately Google and linking up to Google Analytics, in my event action, I can now see all of the variant views. So I can see my product detail view, the 31-inch, 19 ounce bat. So now if we were to change this, I’m sending another product view here and it’s sending another variant, so we can see the 30 inches, 18 ounce. So that’s again taking one single enhanced eCommerce event, attaching a variable to the end of it, and now I’m able to view in bulk what are people, what variants are people using. So was it color, size, et cetera? That can all be sent.
Now let’s look at scenario number four. You go back to our homepage here and look at the video. This is a different trigger. We’re going to go into the matrix here because I’m going to click on a video that shows how to find click classes in GTM. Kind of in the matrix. All right, so now we have a YouTube event that triggered. It triggered a video play that we’re sending to Google Analytics, and let’s just expand this out, and you’ll see you have the event action, the video play, and the video name of How to Find Click Classes in GTM. In this case, I actually have a percentage at the end at zero. So all I did was I clicked on a video, it triggered an event and it automatically grabbed the YouTube video name. Let’s see how that looks in Google Tag Manager.
Here’s our single event. We had the video play with the video title variable. This is a native variable inside of Google Tag Manager and then we have the video percent. So if I were to watch 25, 50, 75% of the video, we would see this trigger additional events as well. So we’d be able to see and track in bulk how far people are actually watching through my video or other videos on the page. So that’s example number four. That’s pretty cool because you can just set up a video tag and trigger instead of having it just in the homepage category, you can have it site-wide, one tag, one trigger, and it’s tracking every video on your site, every video play, every video stop and all their percentages. That’s very powerful and you can see how simple it is to create.
Now we’re going to show you a bonus. I mentioned in the beginning that not only can you use variables inside of your events, so we can expand out the amount of data just through a single tag, now let’s look at an example of applying a variable to a trigger. One common request and the thing that we’ve worked on for a lot of our Elevar customers is looking at products that are sold out or low inventory versus high inventory: Is that driving or changing behavior for the users’ purchase journey? In this case we have a GA event that we’re calling low inventory. It’s tracking on product pages and you can see the event action that we have here is a variable of the product skew, the name inventory and then the variable that actually tracks the inventory.
So again we have skew, the inventory and the actual quantity. So that’s a pretty cool event just on its own. The kicker is we don’t necessarily want to send an event every single product view. We kind of already have that through our typical enhanced eCommerce views. We just want to see different events when inventory is below three, so we can see how that’s driving purchases versus non-purchases. In this case we have the product detail view, which is an event, a standard event that we have and we are setting a rule to only fire trigger this product detail event when the inventory, so we’ll look at this variable here, this is all the list of variables that come in our Shopify app, the inventory is less than three.
Again, we have an event where we want to track how often people are viewing products that are low inventory and how that affects conversion rate. Let’s see that in action here. We’ll reload this page and we’ll reload another product page that I have set up here. All right. Looking at this product page, we’ll take a look at the data layer. Scrolling down here and we see the inventory quantity that we have is four. Remember the rule, the trigger is we only want to fire this event if the quantity is less than three. So you’ll see a tag is fired on this page does not contain that low inventory tag. If we go to our second product here, you’ll see that the low inventory did fire. We’ll go into the data layer here. Sure enough, inventory quantity is two and that tags fired and now it’s available in Google Analytics. So we can see right here.
So that’s four ways, plus four ways to apply variables to your events, to really broaden your amount of data in minimal time, and a bonus way to apply variables to your triggers so you can get even more creative with how you’re sending data and limiting, again, miscellaneous or maybe junk data that you might be sending to Google Analytics.