Unlimited Calculated Metrics - Free Download

Introduction to Nested Variables

Hi there I’m Chris and welcome to another video here at Digital Metrics Guru. Today we’re going to talk about nested variables within Google Tag Manager.

Basically what nested variables means is that we’re going to create a new variable based off of an already created variable. One way that I really like to use this in my workflow is with creating custom metrics inside of Google Analytics. These metrics typically need to result in a one or a zero. It could be a few other numbers in there, but that’s typically what people will need.

Let’s walk through the process of how that exactly works. Before we do that I would do want to direct you over to DigitalMetrics.Guru/05download. Go over there and download the whitepaper on how to further utilize a nested variable, along with some of the top variables to create. Again that’s DigitalMetrics.Guru/05download. Let’s get into the demonstration.

Initial GTM Setup

So we’re over here in Google Tag Manager and I’m going to jump right in. I have a tag already created called content completion. If you click on that, basically what it does is to try to determine whether or not somebody looked all the way through a blog post.

I’ll take you through the tag quickly. It’s an event tag, content completion is the category and then we have the action that’s called scroll depth threshold. This displays the percentage of vertical scroll using a built-in variable within Google Tag Manager. It says that somebody has scrolled a certain percentage through the page. That can be 10%, 25%, 50%, 75%, 90%, or one-hundred. We want people that really scroll at least 90% of the way through the content.

The label gives the page path, which is the page that they were on. So one of the things that I’ve set up to go along with this action is a custom metric within Google
Analytics that checks, did somebody complete content. We could just call it simply content completion. So what you want to do here is set up within Google Tag Manager whether or not that should be sent as a custom metric over to Google Analytics.

Starting the Custom Metric

Within this tag here if you click to edit it, you can scroll down and you’ll have custom dimension here, that’s just the blog title, but then custom metrics are right here. Go ahead and add a new custom metric. If you’re not familiar with custom metrics there’s a lot of different resources and things within Google and right here on Digital Metrics Guru that can get you more familiar with custom metrics.

Now go ahead and add a new custom metric. The index for this example is two, though it’s going to be different for whatever metric you might be setting up. The value typically is either a 1 or a 0 either, however right now every time this event goes you don’t want it to take a 1 or else it’s going to say that there was content completed at every scroll breakpoint. You only want a one to tick for a 90% scroll.

Unlimited Calculated Metrics - Free Download

Creating Nested Variables

What you do is create a new variable here by clicking the little Lego button. Then you’ll choose to create a new variable. I’ve called this content complete but you call it whatever you would like, If you have anything like this up in your site. You’re going go create a new variable for this and for most nested variables you’re going to use a lookup table. It’s going to load the lookup table and the lookup table is going to ask you what variable do you want to start from.

So you’ll remember back from the action within the event we had the scroll depth threshold. You’re going to select that and when you add a new row what you’ll put in the input is whatever the scroll depth threshold returns. That’s what you want to put into it so really you don’t want it to fire on 10%, 25%, 50%, 75%, or 100%. You only want it to fire at 90% that’s what is deemed a content completion.

Go ahead and type in 90 and remember this the threshold doesn’t show the percentage so we just need 90 here. Then the output should be a 1 because you want it to tick 1 for that custom metric.
Now go ahead and add a little bit of a fail-safe. Add a different row and type in 90% just in case and put a 1 there too.

Then set your default value also. You don’t have to do this but you can set it to a zero to make sure that anything else that comes through on scroll down threshold is definitely not going to send a 1 over to that custom metric.

Finishing the Tag

This is as simple as it is to create a nested variable. So now your nested variable is going to count content completion because it’s based off of the other variable. Go ahead and click save there and it’s going to push you all the way back over to your tag. Now it’s auto populated content complete in the new variable we created. So simply you’ll go ahead and save that and then we can go ahead and preview this to make sure it’s working correctly before we publish.

Go ahead and do that and it’ll load up here and what you’ll do is go over to the blog. Let’s select here custom segments and data studio, one of the recent blog posts. Click over there to see the debugger come up and right now it’s only showcasing Google Analytics base code. As you scroll through here content completion it fired one time. Go in to look at the details it’s actually firing at 25% content completion.

If you click show more right here you’ll see custom metric index two, metric zero, exactly what you want. Now scroll all the way down a couple more times to get it to fire and once it fires three to five times go back here now to this one that we’re looking at here. This is the 75 percentile and you want to look at the 90 percentile.

You’ll find the 90 percent with an action of content completion. Click to show more and you’ll see index two, metric one. That’s exactly what you want to happen! You want a custom metric to fire in the index position of two once it gets that 90 percent level. That’s as simple as it is to create custom nested variables within Google Tag Manager.

Conclusion

You can do this in a lot of different ways as I said it works very well when you’re pushing custom metrics through nested variables over to Google Analytics.

Again before I go I want to remind you to go over to DigitalMetrics.Guru/05download. You can download the PDF white paper. Thanks for watching.

Unlimited Calculated Metrics - Free Download

Chris Kujawski

Founder and instructor at Digital Metrics Guru.

A passionate and driven digital marketer, specializing in Google Analytics, Tag Manager and Data Studio. A qualified expert in Google Analytics and Adwords, with more than 10 years experience delivering sound solutions to clients worldwide.

View all posts

Add comment