Lookup tables are one of the most useful and powerful features of Google Tag Manager when it comes to customising and improving your Google Analytics tracking configuration.
Note: This article was first published on rebelytics.com in 2015 and has since then been updated several times and moved to this blog.
In this article, you will find answers to the following questions:
- What are GTM lookup tables?
- How can I track my traffic sources correctly with the help of GTM lookup tables?
- How can I track clicks on social icons with GTM lookup tables?
- How can I reduce the number of tags I need using GTM lookup tables?
If you have any additional questions or if anything remains unclear, please don’t hesitate to leave a comment at the bottom of this page. I normally reply within a couple of days.
So, let’s get started and have a look at some of the cool stuff you can do with lookup tables in Google Tag Manager.
What are lookup tables?
A lookup table in Google Tag Manager is a variable that has the value of another variable as input. Variables, according to Google’s definition, are “name-value pairs for which the value is populated during runtime”.
Google Tag Manager has a number of built-in variables, such as “Page URL”, “Page Path”, or “Page Hostname”. The output value of the variable “Page URL” is the URL of the current page, so on this page it would be:
The value of the variable “Page Hostname” is the hostname of the current page, so for this page it would be “www.searchviu.com”. The variable “Page Path” is the part of the “Page URL” that comes after the “Page Hostname”, so on this page it would be “/en/lookup-tables-google-tag-manager/”.
You can check the output values of all the active variables on your own website by activating the GTM preview mode and going to “Variables”. For the current page, the values of the variables mentioned above are shown like this:
On top of the built-in variables, Tag Manager allows you to define your own set of variables. Lookup tables are a type of user-defined variables and they can be very helpful when you use them in triggers (formerly known as rules), but also when you use them in tags to populate certain fields with dynamic values. Later on in this article, we will have a look at some of the possibilities lookup tables give you.
As mentioned above, lookup tables are a type of variable that have the output value of another variable as input. To get back to our “Page URL” example, I could use the output of this variable as input for a new lookup table variable that I define myself. Remember that the output of the “Page URL” variable always is the URL of the current page. In a lookup table, you always define pairs of values: If the input equals “xyz”, I want the output to be “123”. If the input equals “abc”, I want the output to be “789”, and so on.
If, for some reason, I wanted to track, let’s say, the mood I was in when I published my blog articles, I could use a lookup table to define a mood value output for every URL input and send the values to Google Analytics in a custom dimension.
This is obviously not a very realistic example for using lookup tables, but don’t worry, we will also look at some real-world examples in a bit.
So if the output of the variable “Page URL” was “https://www.searchviu.com/en/lookup-tables-google-tag-manager/”, I could use a lookup table that defines the value “grumpy” for this page view and send it to Google Analytics.
Here’s what this lookup table would look like in GTM:
I could now use the output value of this lookup table to populate a custom dimension in a Google Analytics page view tag. But let’s just have a look at some real-life examples of lookup tables that actually make sense!
Use a lookup table to track different traffic sources
The first time I came in contact with lookup tables was after reading this brilliant article on the LunaMetrics blog. Jim Gianoglio describes how you can use URL fragments to track different traffic sources in Google Analytics using a lookup table. I love this solution and I have been using it in a slightly modified way on all of my clients’ websites and also here on searchviu.com ever since.
I will quickly walk you through setting this up in Google Tag Manager (V2). The goal of this solution is to be able to track the traffic your social posts and other traffic sources generate without having to use Google’s UTM tracking parameters (the horrible ones that look like this and don’t even fit in a line on this blog:
First, you need to set up a user defined variable of the type “URL”. In the configuration of the variable, select the component type “Fragment”. Make sure you give the variable a clear name that you will remember and recognise, like “URL fragment”. This variable will now have the URL fragment of the current page as output. Here’s what it looks like in GTM:
A URL fragment is the part of the URL that comes after the hash (#), if there is one. So now your Tag Manager configuration is able to read the URL fragments of URLs like this:
- and so on
Do you see where this is heading? You can now tag the links you share on social media or in your newsletter in a much easier and more user-friendly way than with UTM tracking parameters. Next, let’s see how to get this data into Google Analytics.
So why don’t we just send the value of the “URL fragment” variable straight to Google Analytics? Because URL fragments are used for plenty of purposes and we only want to send the values we defined for our different marketing channels to Google Analytics. This is where the lookup table comes in handy: It acts as a kind of filter. Also, wouldn’t it be nice to populate the dimensions “source, “medium” and “campaign”, just like we do with UTM parameters?
Let me walk you through this step by step. First, we need three lookup tables, one for each of the dimensions “source”, “campaign” and “medium”. The input values are the same in all of them (the URL fragments we use for tracking our traffic sources), and the output values are the values we want to show up in the three dimensions “source”, “medium” and “campaign” for each of the input values.
Here’s what the lookup table for the dimension “source” would look like if we wanted to track the traffic sources for the three example URLs above:
The lookup table for the dimension “medium” looks very similar, with the only difference that the output values are changed:
And finally, the lookup table for the medium “campaign”, you get it!
Now, if I visit the URL “https://www.searchviu.com/en/lookup-tables-google-tag-manager/#twitter”, which I would use for sharing this article on Twitter, I see the following values for my new variables in the GTM preview mode:
Next, let’s have a look at the last step that is needed in order to get this data into Google Analytics. All you need to do is to go to your Google Analytics page views tag in Google Tag Manager (or to your Google Analytics settings variable, if you’re using one), and add the output values of your new lookup tables to the fields “campaignSource”, “campaignMedium” and “campaignName” in the section “Fields to set”, as you can see in this screenshot:
The URL fragments “#twitter”, “#facebook” and “#linkedin” now have the same function as the following UTM parameter chains:
Pretty awesome, isn’t it? Shoutouts to Jim Gianoglio for inspiring this method with the Luna Metrics article I linked to above, and to my former colleague and wizard web analyst Sascha Schau, who helped me refine this method when we were working together.
Let’s have a look at some more cool stuff you can do with lookup tables in Google Tag Manager.
Use a lookup table to track clicks on social icons
Another very interesting way to use lookup tables is for the tracking of outbound links. For the social profiles that you link to from your website, you can create a lookup table that defines a descriptive output value for each of the URLs you link to, for example “facebook profile”, “google+ profile”, and so on.
You can now use the output of this lookup table as a condition in a link click trigger and at the same time to populate the values of the events you send to Google Analytics. Here are the steps you need to undertake:
- Create a lookup table that gives a descriptive name to the URLs of the outbound links you want to track. Use the URLs of your social profiles as inputs and the descriptive names as outputs.
- Create a new trigger with the event type “click”.
- Choose the type “link click”.
- Select “Fire on some clicks”, select the name of your new lookup table, and set the condition that it match a regular expression with all the output values of your lookup table, separated by vertical bars, for example: googleplus|linkedin|twitter
- Create a new Universal Analytics Tag and select the track type “event”.
- Use your new lookup table to populate the fields you send to Google Analytics. It makes sense to use the output value in the field “Label” under “Event tracking parameters”.
- In the last step of your Google Analytics tag configuration, select “fire on click” and pick your newly created link click trigger.
This is so easy that it feels like cheating! But we’re already done. Your outbound link clicks are now being tracked in Google Analytics and the data even looks nice because you used a lookup table to set descriptive names.
Use lookup tables to reduce the number of tags you need
If you tried to set up the solution described above without lookup tables, you would probably succeed, but you would need a hell of a lot of tags. So lookup tables help you reduce the number of tags in this case and they do so in many other cases.
You might be using a Google Tag Manager container for several domains. Think about using a lookup table that defines an Analytics tracking ID output for a hostname input. This way you could use one Google Analytics tag to track data in several properties.
Also, with the right combination of lookup tables, you will not need different tags of the same track type any more. One pageview tag, one event tag, one transaction tag (and so on), will be enough in many cases. This makes your Tag Manager account look a lot tidier and it leaves less room for stupid mistakes.
Once you start working with lookup tables you will realise how much time they save you and also how much fun it is to quickly set up things that would have taken an hour before.
If you have any questions or thoughts about this article, please don’t hesitate to drop me a comment!