Understanding Lookup Table Variable in Google Tag Manager

A Lookup table variable is a user defined variable in Google Tag Manager.

As the name suggest this type of variable is used to lookup for the value that matches a given input pattern.

In the context of GTM, the lookup table variable determines whether or not there is an exact match with an input pattern and if there is an exact match then return the corresponding output value.

If there is no exact match then return ‘undefined’ (unless the default value has been set).

By using lookup table variables you can greatly reduce the number of tags required to send hit data (esp. ‘event’ data) to Google Analytics.

A lookup table variable is made up of input variable and lookup table:

The lookup table is made up of one or more rows and two columns.

You can add as many rows as you like to a lookup table. However the number of columns in the lookup table will always remain two.

The first column of the lookup table is labelled ‘Input’ and is used to specify ‘Input Patterns’:

For example:

You can use any string as input pattern. You can also use any GTM variable as an input pattern. But you can not use regular expression as input pattern.

The second column of the lookup table is labelled ‘Output’ and is used to specify ‘Output values’.

For example:

From the screenshot above we can conclude following:

#1 If the output of the input variable matches the input pattern ‘start’ then set output value to ‘video started playing’.

#2 If the output of the input variable matches the input pattern ‘complete’ then set output value to ‘video finished playing’.

The corresponding output value of the last matched pattern is the value returned by a lookup table variable. It is important to remember that this match needs to be an exact match and is case sensitive.

You can reference/call any GTM variable (including another lookup table variable) from within the output value field:

You can also reference lookup table variable in custom HTML tags and custom JavaScript variables.

Get the E-Book (62 Pages)

Introduction to Input Variable

Input variable is the GTM variable (either built-in or user defined variable) whose output is checked against the input patterns you specify in the ‘Lookup Table’:

The output of the input variable is checked against each input pattern, row by row, from top to bottom in the lookup table.

When the output of an input variable last matches an input pattern, the corresponding output value of the last matched input pattern is resolved and then returned by the lookup table variable.

If no match is found then the default value is returned.

If the default value has not been set and no exact match is found then the lookup table variable returns ‘undefined’.

For example, let us consider a built-in variable {{Video Status}}

This variable can return one of the following values at run-time:

  1. start
  2. complete
  3. pause
  4. seek
  5. buffering
  6. progress

In other words, following are the possible outputs of the {{Video Status}} variable:

  1. start
  2. complete
  3. pause
  4. seek
  5. buffering
  6. progress

If you use {{Video Status}} variable as an input variable then its value will be checked against each input pattern, row by row, from top to bottom in the lookup table:

When the output of the {{Video Status}} input variable last matches an input pattern, the corresponding output value of the input pattern is resolved and then returned by the lookup table variable.

For example, let us suppose the output of the {{Video Status}} input variable at run-time was ‘complete’.

Now when the lookup table variable is referenced/called, the output of the {{Video Status}} input variable will match the input pattern ‘complete’ and the corresponding output value ‘video finished playing’ will be returned by the lookup table variable:

Another example,

If output of the input variable {{Video Status}} is ‘start’ at run time then it will match the ‘start’ input pattern.

And when the input variable matches the input pattern ‘start’ then the output value will be set to ‘video started playing’ and the lookup table variable ‘Video Player State’ would return the string ‘video started playing’:

Another example,

If output of the input variable {{Video Status}} is ‘pause’ at run time then it will not match any input pattern.

And when the input variable does not match any input pattern then the lookup table variable ‘Video Player State’ would return ‘undefined’ (unless a default value has been set):

Another example,

Consider following lookup table:

If output of the input variable {{Video Status}} is ‘start’ at run time then it will not match any input pattern including the input pattern ‘start playing’. This is because only ‘exact match’ operation is carried out in case of lookup tables and ‘start’ is not an exact match of ‘start playing’

And when the input variable does not match any input pattern then the lookup table variable ‘Video Player State’ would return ‘undefined’:

Another example,

Consider following lookup table:

If output of the input variable {{Video Status}} is ‘start’ at run time then it will match the last matched input pattern.

So the output value will be set to ‘video started’ and the lookup table variable ‘Video Player State’ would return the string ‘video started’:

Usually input variable should return single value at a time. But sometimes it can run multiple values. In that case all of the values returned by input variable should match one of the input patterns.

For example, consider following custom JavaScript variable which returns an entire array:

Now if we use this custom Javascript variable as an input variable then the output of the input variable will return all of the following values at run time: start,complete,pause,seek,buffering,progress

So unless one of your input pattern is ‘start,complete,pause,seek,buffering,progress’, your lookup table variable will return ‘undefined’:

You can set default value for your lookup table variable by clicking on the ‘Set Default Value’ checkbox and then entering the default value:

If you have set the default value to ‘no match’ then when the output of the input variable does not match any of the specified input patterns, the lookup table variable returns ‘no match’ instead of ‘undefined’.

It is important to note that if an input variable does not match any given input pattern then GTM will not throw any error or give you a warning message.

Another example,

Consider following lookup table:

If output of the input variable {{Video Status}} is ‘Start’ (note the word start with capital letter) at run time then it will match the first input pattern and not the second. This is because the value lookup is always case sensitive.

So the output value will be set to ‘video started playing’ and the lookup table variable ‘Video Player State’ would return the string ‘video started playing’:

How to create a lookup table variable?

Step-1: Login to your GTM account and then click on the ‘Variables’ link in the left hand side menu:

Step-2: Scroll down to ‘User-Defined Variables’ section and then click on the ‘New’ button:

Step-3:Select ‘Lookup Table’ from the ‘Choose Variable Type’ menu

Step-4: Enter a name for your Lookup table variable. You will later reference the lookup table variable by this name.

Step-5: Select Input variable from the drop down menu:

If your input variable do not already exist then create new one. You need an input variable in order to use a lookup table variable.

Step-6: Enter input pattern and its corresponding output value in the lookup table, row by row, from top to bottom:

Step-7: Specify the default value for your lookup table variable by clicking on the ‘Set Default Value’ checkbox and then entering the default value:

Here when the output of the input variable does not match any of the specified input patterns, the lookup table variable returns ‘no match’ instead of ‘undefined’.

Use Case for Lookup Table Variable

Lookup table variables are ideal for using one tag for sending different event hits.

Read this article: Video Tracking via YouTube Video Trigger In Google Tag Manager where a lookup table variable is used in an event tag to return the current video player state.

 

"How to use Digital Analytics to generate floods of new sales and customers"

(Even if you are completely new to Analytics)

 

What You’ll Learn On This FREE Web Class!

#1 The number 1 reason why most marketers and business owners are not able to scale their advertising and maximise sales. 

#2 Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics. 

#3 The number 1 reason why conversion optimization is not working for your business. 

#4 How to advertise on any marketing platform for FREE with an unlimited budget.

#5 How to learn and master digital analytics in record time.

 
 

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!