A lookup table in Google Tag Manager makes it much simpler to manage lots of values in your tracking setup. It can drastically reduce the number of tags required and turn your messy GTM into a neat environment.

It's especially useful with larger setups where you have multiple tracking requirements and flexible to accommodate new tracking needs as they arise. You can easily add or remove values from your lookup tables, and not worry about having to change any codes.

The lookup table variable allows you to define a set of key-value pairs where the output variable (the value that you are sending to Google Analytics) is linked to the identifier (the key).

It works like this: When [input variable] equals to  _______, set [this output variable] to_______.

how lookup table variable works in gtm

For example, you could use the lookup table for:

  • Assigning different Google Analytics property IDs for various domains/hostnames, eg. when [website hostname] equals to littledata.co.uk, set [property ID] to UA-010101 (see example below)
  • Setting different pixel or conversions IDs for different country websites, eg when [website country code] equals to 2, set [pixel ID] to 88779 (requires having website country code variable defined)
  • Defining your event categories, actions and labels (see example below)

Remember! There’s no limit to how many values you can have in the lookup table, but the fields are case sensitive.

So if you have multiple capitalisations of some input, then include all of them in the lookup table and assign the same output for each.

capitalisations in lookup table variable

I have previously explained setting up the tracking of user actions as events in GTM, but when you need to track multiple events, one tag just doesn't cut it anymore.

And instead of creating several tags to cover each event or action, here's how you would create the lookup table to cover multiple values in one place.

Creating lookup table variable for event parameters

In the Littledata software interface, you get an option to switch between different report types or view them all.

using lookup table in google tag manager

I want to track when people click on different report types, so instead of creating 5 different tags for each user action, I will set up a lookup table to cover all of them in one place.

But firstly I need to know which variable to use as the input. You can only have one type of input variable per the lookup table so you want to pick a variable type that applies to each (ideally).

For this, I will check how each report type option has been set up in the code by inspecting the element (inspect/inspect element depending on the browser you're using and usually accessible via right click).

Here's how each report type has been set up:

<a href="/report-list/m2i4MnmXcewDSzZ3c/all" class="current" id="ga-all">All <span class="count">120</span></a>

<a href="/report-list/m2i4MnmXcewDSzZ3c/trends" class="" id="ga-trends">Trends <span class="count">80</span></a>

<a href="/report-list/m2i4MnmXcewDSzZ3c/pages" class="" id="ga-pages">Pages <span class="count">37</span></a>

<a href="/report-list/m2i4MnmXcewDSzZ3c/tips" class="" id="ga-tips">Tips <span class="count">3</span></a>

<a href="/report-list/m2i4MnmXcewDSzZ3c/benchmark" class="" id="ga-benchmark">Benchmark <span class="count">0</span></a>

Looking at the above, I can see that each report type has a unique ID - here that's the best one to use.

Now to set this up, go to Variables, click ‘New’ and select 'Lookup Table' as your variable type.

For the input variable, I will use {{Click ID}} as explained above, but you, of course, use whatever unique identifier you have available.

event tracking with lookup tables in google tag manager

For your output, you want to define the event action you are going to send to the Events report in Google Analytics.

gtm lookup table event action

Should you set the default value?

You can set a default value for the output when there is no match found in your table.

With the event tracking, I sometimes find it useful to enable to identify if I set up my tag correctly. If my trigger ends up being too broad, the default value option will pick up additional values not defined in the table. I will then see these values in Google Analytics reports and this way I can tidy up the trigger to be more accurate.

So this is what your variable should look like now.

lookup table variable in gtm v2

Click ‘Create Variable’ and there you have it.

In your GA event tag, the newly created variable would look like this.

using lookup table variable in gtm tag

Other uses

Multiple Google Analytics properties

If you have a single GTM container installed on multiple domains but you're tracking them across different Google Analytics properties, you want to ensure that you're sending the data to the correct one.

Instead of having multiple variables to store different property IDs, you can have them all neatly in the same table defined by the hostname.

This way any tracking activity on each site will go to its own dedicated property.

store ga property id values in gtm lookup table

Excluding test or other data

If you want to make sure that any data outside of your main site goes to a test or other Google Analytics property, you can do so by setting the default value.

The default value is the output that is not found in the table. With this setup, any activity tracked on www.mainsite.com goes to property ID UA-121212.

If the activity wasn't on www.mainsite.com, then it sent to property ID UA-121212-2.

exclude test data lookup variable gtm

Use lookup tables for something else? Confused? Get in touch or comment below!