Lookup tables in Google Tag Manager (GTM) allow you to map one value to another based on predefined rules. This can be useful for translating or transforming data before sending it to tags, such as Google Analytics. Here’s a step-by-step guide on how to create and use lookup tables in GTM:
Table of Contents
Toggle1. Access Google Tag Manager
- Sign in to Google Tag Manager:
- Go to Google Tag Manager and sign in with your Google account.
- Select Your Container:
- Choose the container where you want to create the lookup table or create a new one if you haven’t already.
2. Create a Lookup Table Variable
- Navigate to Variables:
- In your GTM workspace, click on
Variables
in the left-hand menu.
- In your GTM workspace, click on
- Add a New User-Defined Variable:
- Click on
New
under User-Defined Variables.
- Click on
- Choose Variable Type:
- Select
Variable Configuration
and chooseLookup Table
.
- Select
- Configure the Lookup Table:
- Enter a name for your variable (e.g., “Custom Lookup Table”).
- Define your lookup table rules:
- For each input value (e.g., a variable or constant), specify the output value it should map to.
- You can add multiple rows to define different mappings.
- Save the Variable:
- Click
Save
to save your lookup table variable.
- Click
3. Use the Lookup Table Variable in a Tag
- Create or Edit a Tag:
- Navigate to the tag you want to use the lookup table variable with, or create a new tag.
- Set Up Tag Configuration:
- Configure the tag as usual, but instead of hardcoding values, use the lookup table variable as a dynamic value.
- Use the Lookup Table Variable:
- Wherever applicable in the tag configuration (e.g., event parameters, fields), use the lookup table variable as a value by referencing its name.
4. Test Your Setup
- Enter Preview Mode:
- Click
Preview
in the GTM workspace to enter preview mode.
- Click
- Test Your Tags:
- Navigate to the page where your tag is deployed and trigger the event or action associated with it.
- Verify in Preview Mode:
- In the GTM preview mode, check that the lookup table variable resolves correctly and that the tag fires with the expected values.
5. Publish Your Changes
- Submit Your Changes:
- Once you’re satisfied with the setup and have tested it thoroughly, click
Submit
in GTM to submit your changes.
- Once you’re satisfied with the setup and have tested it thoroughly, click
- Publish Your Container:
- Add a version name and description, then click
Publish
to make your changes live.
- Add a version name and description, then click
Tips for Using Lookup Tables:
- Conditional Mappings: You can use conditions in your lookup table to handle different scenarios or cases.
- Dynamic Inputs: You can use variables as inputs in your lookup table, allowing you to dynamically map values based on user interactions or other factors.
- Regular Expressions: GTM allows you to use regular expressions in your lookup table to match patterns or extract specific parts of a value.
Example Use Case:
Let’s say you have a website with different product categories represented by numbers (e.g., 1 for Electronics, 2 for Clothing). You want to track these categories in Google Analytics with their corresponding names. You can create a lookup table variable to map category numbers to names, then use this variable in your Google Analytics tag to send the category names instead of numbers.
By following these steps and tips, you can effectively create and use lookup tables in Google Tag Manager to transform and map values based on predefined rules, enhancing the flexibility and power of your tracking implementations.