Creating and using lookup tables in Google Tag Manager (GTM) is an effective way to map values from one set to another, allowing for data transformation and enhancing tracking capabilities. Lookup tables can be particularly useful for tasks like converting codes to descriptive names, categorizing traffic sources, or changing data formats before sending them to analytics platforms. Here’s a step-by-step guide on how to create and use lookup tables in GTM.
Step 1: Access Google Tag Manager
- Log in to GTM: Go to Google Tag Manager and log in to your account.
- Select Your Container: Choose the container you want to work with.
Step 2: Create a New Variable
- Navigate to Variables:
- In the left sidebar, click on Variables.
- Create a New User-Defined Variable:
- Click on the New button in the User-Defined Variables section.
- Choose Variable Type:
- In the variable configuration panel, click on Variable Configuration.
- From the list, select Lookup Table.
Step 3: Configure the Lookup Table
- Define the Input Variable:
- In the Input Variable field, choose the variable you want to look up values from. This could be a built-in variable like
Page Path
,Page URL
, or a custom variable you’ve created.
- In the Input Variable field, choose the variable you want to look up values from. This could be a built-in variable like
- Add Lookup Table Entries:
- In the Lookup Table section, you will define key-value pairs. Click on Add Row to create a new entry.
- In the Input column, enter the value you want to match (the key).
- In the Output column, enter the value you want to return when the input matches the key.
For example:
- Input:
source1
- Output:
Source Name 1
You can add as many rows as necessary to map all desired values.
- Set Default Value (Optional):
- At the bottom of the lookup table configuration, you can set a default value. This value will be returned if none of the keys match the input variable.
- Name the Variable:
- Click on the Variable Name area at the top and give your lookup table variable a descriptive name (e.g.,
Source Lookup Table
).
- Click on the Variable Name area at the top and give your lookup table variable a descriptive name (e.g.,
- Save the Variable:
- Click Save to save your new lookup table variable.
Step 4: Using the Lookup Table Variable in Tags
- Create or Edit a Tag:
- Navigate to Tags in the left sidebar.
- Create a new tag or edit an existing one where you want to use the lookup table variable.
- Insert the Lookup Table Variable:
- In the tag configuration, wherever you want to use the output from the lookup table (e.g., in a field like Event Label, Custom Dimension, etc.), click on the variable selector (the curly brackets
{}
) and choose your lookup table variable.
- In the tag configuration, wherever you want to use the output from the lookup table (e.g., in a field like Event Label, Custom Dimension, etc.), click on the variable selector (the curly brackets
- Finish Configuring the Tag:
- Complete any other necessary settings for your tag (such as triggers) and click Save.
Step 5: Test the Lookup Table
- Preview Mode:
- Enable Preview Mode in GTM to test your changes. Click on the Preview button in the top right corner of the GTM interface.
- Visit Your Website:
- With preview mode enabled, go to your website. This will open the GTM Debug Console.
- Check Data Layer Values:
- Perform actions on your site that will trigger the tag using the lookup table variable.
- In the GTM Debug Console, check the values being passed through your lookup table variable. Make sure that the input values match your keys and that the correct outputs are being returned.
- Debug and Adjust:
- If the lookup table is not returning the expected results, review your entries to ensure they are correct. Adjust your input values and outputs as necessary.
Step 6: Publish Changes
- Submit Your Changes:
- Once you have confirmed that everything is working as expected, exit preview mode.
- Click the Submit button in GTM to publish your changes.
Additional Tips
- Complex Mappings: For more complex scenarios, consider creating multiple lookup tables or using additional GTM features like Custom JavaScript Variables to manipulate data before or after the lookup table process.
- Naming Conventions: Use clear and consistent naming conventions for your variables to make managing and understanding your GTM setup easier in the future.
- Documentation: Keep documentation of your lookup tables, especially if they serve critical tracking functions, to ensure that team members can understand their purpose and configurations.
Conclusion
Using lookup tables in Google Tag Manager provides a powerful way to manipulate and transform data before it is sent to analytics tools. By following these steps, you can effectively set up and utilize lookup tables to enhance your tracking capabilities, ensure accurate data reporting, and streamline data management across your digital marketing efforts. Regular testing and adjustment will help maintain the effectiveness of your lookup tables as your tracking needs evolve.