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. 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 “http://www.rebelytics.com/lookup-tables-google-tag-manager/”. The value of the variable “Page Hostname” is the hostname of the current page, so for this page it would be “www.rebelytics.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 “/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. So if the output of the variable “Page URL” was “http://www.rebelytics.com/lookup-tables-google-tag-manager/”, I could use a lookup table that defines the value “grumpy” for this pageview 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 rebelytics.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: “?utm_source=facebook&utm_medium=social&utm_campaign=facebook-posts”).
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.
So the next step is to create a variable of the type “Lookup Table” and choose our recently created new variable “URL fragment” as input value. Now we have to define the rows of the table, so for every channel or network we want to track, we need to define an input-output pair. Note that, even if the input and output are exactly the same, this makes complete sense. The lookup table is acting as a filter here so that you have complete control over the possible outputs of this new variable. The lookup tables that I use for this purpose often look like this:
And we’re almost done! Now you can use your new lookup table to populate a custom dimension in your Universal Analytics tag and send the data to Google Analytics. I will soon dedicate an entire post to tracking traffic sources correctly and analysing the data in Google Analytics. Let’s now move on to 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 above described solution without lookup tables, you would 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 tag manager container for severel 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.
Did you enjoy reading this article? Say thanks by sharing it: