GTM has several useful variables. In this video, I am going to share with you the top 10 GTM Variables we use here in Measureschool and give you a brief overview of each variable.
DataLayer variable: https://www.youtube.com/watch?v=PV3KBpbKXsA
Constant Variable: https://www.youtube.com/watch?v=8kDTTcAla4A
GA Settings Variable: https://www.youtube.com/watch?v=XFvKe76oebo&t=615s
Dom Variable: https://www.youtube.com/watch?v=nxEYZthbzp4&t=308s
Lookup Table Variable: https://www.youtube.com/watch?v=xX7_QnU6Ga0
In this video, you’re gonna learn about the top 10 variables you should use within Google Tag Manager. All and more coming up.Hey there measuregeeks. Julian here
back with another video for you. Today we want to talk about Google Tag Manager variables. Now variables are like placeholders within Google Tag Manager that let us fill our tags, triggers, and even other variables with this placeholder information. They get resolved during the page load and can hold different values. Now, I don’t want to get too much into how variables actually work. But I want to tell you about the 10 variables that I use most often within my Google Tag Manager deployments. So without further ado, we got lots to cover. So let’s dive in.
All right, our first variable is the datalayer variable. If you have a nice datalayer on your page, you’ll be able to pull out the data that is stored in the value of datalayer and transferring this over to a datalayer variable right here. To do this, simply go over to Google Tag Manager and create a new variable of the type datalayer variable. And what you would need to enter is simply the key that you want to pull out. So in this case, we look at the datalayer and we want to pull out the value of our visitor logged out, we will need to know the key which is written here in black, the visitor type, just enter this into the data layer variable name field and you’ll be able to then pull this out of the data layer and store it in a variable. Now there are a few other tricks to this data layer variable. But we have a separate video on it that I’m going to link up down below if you want to check it out.
Next up our auto event tracking variables. Now if you haven’t auto event trigger installed, so for example, the click trigger, or one of the user engagement triggers, you will likely want to enable all your auto event tracking variables. What does this mean? So for this click trigger, you go over to your variable menu and configure your built in variables. And here you will find certain auto event variables that you can enable, just click them and they will be enabled for you in your account. Then you can head back and try out your click trigger. If it’s already installed, we just head over to our page, reload this, click on the Add to Cart button for example. And then we should see in our variable menu, the enabled auto event variables right here. And not all of them always get filled. But if they get filled, they have some important information that lets us distinguish our different cliques from each other. And make sure our filter within our auto event trigger is correctly filled. So for example, here the classes is transferred, or the add to cart, which is the click text of our button. And this is vital information that we can later use within our trigger, but then also within our tech. So definitely enable your auto event trigger variables if you are using an auto event trigger. Number three, the Google Analytics settings variable. Now when would a Google Analytics settings variable be useful? Well, if you have Google Analytics installed through Google Tag Manager, and you have several tags that are sending data over to Google Analytics, you might know the tech template of Google Analytics where you have many different settings that you can choose right here. And a settings variable is simply a variable that will fill out all these different fields based on one variable. So for example, here we have the tracking ID in here. And this is something we would need to repeat all over again, in our other event tags, for example. So for convenience sake, we can simply build a new Google Analytics settings wearable that will prefer this tracking ID field, who can go and build a new Google Analytics setting circle, and filling our tracking ID once save this. And Henceforth, we have it available here in our settings, terrible drop down and can choose this. And we will get rid of the Enable override settings and this tag. So all the settings that would normally be put into these fields here are now governed by one central variable, our Google Analytics settings terrible. So it makes our lives easier because we know that this is all governed by one single variable, our Google Analytics settings terrible. It also makes it easy to expand our tracking, because we will be able to go into the settings variable itself. And let’s say one or two sent a custom dimension with all of our patrons and events, we simply wouldn’t need to go into the settings terrible, and then choose the right dimension right here. So we’ll add a custom dimension and can use another variable to fill this out.
The same is true if you had a setting that you want to set on all pages, like a humanized RP to true or the cross domain tracking settings wants to find in the Google Analytics settings arable this will obviously also transfer to all your tags that you have already installed. So the Google Analytics area circle is essential working with Google Analytics and Tag Manager. Next up the URL query variable. Or this variable is particularly useful if you see any kind of query string in your URL. And you would like to get this information for example, here would be the search term that was entered into the search bar into some kind of tag or use it in your triggers. So with the URL variable, you can easily pull this out, just go over and create a new variable of the type URL, and then choose as the component type, the query type, then you just need to know the query key. And the key is whatever is in front of the equal sign of your desired value. In our case, it would be simply s and give it all the name.
And we should now have it available as a variable to us inside of our tax entries. Next up the referral variable. This is a variable that is already built in and also enabled by default. So you should be able to find it under your variable menu really easily, right here. Now, what does this variable tell us, it’s actually the URL that the user just came from, before he entered this page. And since the refer to this website, this can be quite useful if you just entered the page. So for example, right here, if I go on the search result from Google and come to the page, our referral should have something to do with Google. So let’s look into the referral variables. And here we go, we have a refer from google.com. And we could utilize this to always fire a tag when somebody comes from google.com, for example, or we could also utilize this in our other tags to send that data to our analytics tools. And our six variable is the first party cookie variable. Oh, if you would navigate around with Google Tag Manager on your page, you know that the preview mode reloads every time you go to a new page. That also means the page you dumb ready and window loaded, appear new in your preview mode, and the data layer gets filled with new data. Unfortunately, Google Tag Manager cannot remember anything that was going on beforehand. Each page load means a new loading of Google Tag Manager and web development, you can persist the data. And commonly there are cookies used to do this, you can set cookies with Google Tag Manager. But that’s a topic for another video. For now, we just want to view the cookies that are set on our browser will open up our chrome menu here to go into the developer tools. And here we get some useful information under the application tab. And cookies right here we can see what data was set through different code on our website.
Now in some cases, there’s more useful information. In other cases, it’s unusable because you don’t really know what it exactly means. But as I said, you could actually also set your own cookies. For example, this cookie here is this user newsletter subscriber was set to true probably he came from a newsletter source. And therefore we can identify this user and we have written this information to the cookie, how can we make the useful now in Google Tag Manager, we can pull out this value from our cookie. By building a first-party cookie variable, all you need to do is go over to Google Tag Manager and under the user-defined variables will choose a first-party cookie variable as our type. And we need to have the nickname in our case, the cookie name is newsletter subscriber gives us all a name. And the should now pull out the right value from our cookie. And voila, here we go. So maybe have a look in your cookies. What useful information you could pull out with this first-party cookie variable.
Next up the DOM element variable. Now what does Dom stand for it stands for the document object model. This is how our site is marked up and we can simply right click on any element on our website and click on Inspect Element and Chrome, which will open up the elements Fein here and give us the visual representation of the document object model with the DOM element variable will be able to pull out any kind of node that we are interested in and get either a attribute or the text in between those elements. So for example, here, if I wanted to pull out the card menu, and the amount of this card menu, I would need to either know the ID or this element doesn’t have an ID or the CSS selector. Luckily, there is a class of amount which we can utilize in our variable really easily. So let’s head over to Google Tag Manager. And he under variables, we’ll go into our new user defined variables and click on the DOM element. For variable. The selector method is this time CSS selector because we don’t have an ID, and we had a class with red dot here and amount you need to know a little bit of a CSS selectors in order to do this protectively. And then we can choose the attribute that we want to pull out. Since we want to pull out the text, we can leave this empty for now. And let’s give this all the name. Save this. And let’s try this all out.