How to Create and use Lookup Tables in Google Tag Manager

Author:

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:

 1. Access Google Tag Manager

  1. Sign in to Google Tag Manager:
  2. 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

  1. Navigate to Variables:
    • In your GTM workspace, click on Variables in the left-hand menu.
  2. Add a New User-Defined Variable:
    • Click on New under User-Defined Variables.
  3. Choose Variable Type:
    • Select Variable Configuration and choose Lookup Table.
  4. 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.
  5. Save the Variable:
    • Click Save to save your lookup table variable.

 3. Use the Lookup Table Variable in a Tag

  1. Create or Edit a Tag:
    • Navigate to the tag you want to use the lookup table variable with, or create a new tag.
  2. Set Up Tag Configuration:
    • Configure the tag as usual, but instead of hardcoding values, use the lookup table variable as a dynamic value.
  3. 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

  1. Enter Preview Mode:
    • Click Preview in the GTM workspace to enter preview mode.
  2. Test Your Tags:
    • Navigate to the page where your tag is deployed and trigger the event or action associated with it.
  3. 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

  1. Submit Your Changes:
    • Once you’re satisfied with the setup and have tested it thoroughly, click Submit in GTM to submit your changes.
  2. Publish Your Container:
    • Add a version name and description, then click Publish to make your changes live.

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.