At some point in every GTM implementation, you need to map one value to another. A page path maps to a category. A product ID maps to a product name. A URL pattern maps to a campaign label. The naive solution is a long chain of if/else conditions in a Custom JavaScript variable. The right solution is a Lookup Table or RegEx Table — GTM's built-in mapping variable types that handle this cleanly without custom code.
What Is a Lookup Table?
A Lookup Table variable takes an Input Variable and compares its value against a list of Input → Output mappings. When it finds an exact match, it returns the corresponding output. If no match is found, it returns a default value (or undefined if you don't set one).
When to Use It
Use Lookup Tables for exact string matching — when the input values are known, finite, and consistent:
- Mapping page paths to content categories (
/blog/→Content,/pricing/→Conversion) - Mapping GTM environment names to analytics property IDs (dev vs prod)
- Mapping country codes to region labels
- Mapping product category IDs to human-readable category names
How to Create One
- Go to Variables → New → Lookup Table
- Set the Input Variable to the value you want to map from (e.g.
{{Page Path}}) - Add rows: Input → Output (e.g.
/contact/→Contact Page) - Set a default value for when no match is found (e.g.
Other)
What Is a RegEx Table?
A RegEx Table works the same way as a Lookup Table, but instead of exact matches, each input is a regular expression pattern. The variable tests the input value against each pattern in order and returns the output for the first match.
When to Use It
Use RegEx Tables for pattern matching — when the input values vary but follow predictable patterns:
- Mapping URL patterns to page types (
^/products/.+→Product Page) - Classifying blog post URLs by section (
^/blog/gtm/→GTM Content) - Identifying checkout steps from dynamic URLs (
/checkout/step-[1-4]/→Checkout) - Extracting and normalising parameter values that may appear in different formats
How to Create One
- Go to Variables → New → RegEx Table
- Set the Input Variable
- Add rows: each Input is a regex pattern, Output is the returned value
- Check Ignore Case if capitalisation might vary
- Set a default value
Patterns are tested top-to-bottom. Put more specific patterns first — a broad catch-all at the bottom acts as your default.
Practical Example: Page Type Classification
Suppose you want to tag every GA4 event with a page_type parameter. Your site has these URL patterns:
- Homepage:
/ - Blog posts:
/blog/[slug]/ - Service pages:
/services/[slug]/ - Pricing:
/pricing/ - Contact:
/contact/
Create a RegEx Table with Input Variable {{Page Path}} and these rows:
^/$→Homepage^/blog/.+→Blog Post^/services/.+→Service Page^/pricing→Pricing^/contact→Contact
Default: Other. Now use this variable as the page_type parameter in your GA4 Configuration tag — every event automatically includes the page type without any custom code.
Practical Example: Environment-Based Property IDs
A common GTM pattern is to send data to a dev analytics property during development and a production property on the live site. Use a Lookup Table with Input Variable {{Environment Name}}:
Live→G-PROD123456Now→G-DEV789012(GTM Preview environment)
Reference this variable as the Measurement ID in your GA4 Configuration tag. Now you'll never accidentally send dev traffic to your production property.
Lookup Table vs Custom JavaScript: When to Choose Each
| Scenario | Best Choice |
|---|---|
| Finite list of known exact values | Lookup Table |
| URL patterns, varying strings | RegEx Table |
| Conditional logic with multiple inputs | Custom JavaScript |
| Value needs computation or transformation | Custom JavaScript |
Lookup and RegEx Tables win on maintainability — anyone with GTM access can update the mapping without understanding JavaScript. Custom JavaScript variables require code review when updated and are harder for non-technical team members to modify.
Limitations to Be Aware Of
- Lookup Tables only support exact string matches — no partial matching, no case-insensitive option
- RegEx Tables can get slow with very large lists (50+ patterns) — consider splitting into multiple tables
- Neither type supports multi-input logic (if A AND B then C) — for that, use Custom JavaScript
Conclusion
Lookup Tables and RegEx Tables are some of GTM's most underused features. They replace messy conditional JavaScript with clean, readable configuration that any team member can maintain. Any time you find yourself writing if (x === 'a') return '1'; else if (x === 'b') return '2'... in a Custom JS variable, a Lookup Table is probably the better answer.
If your GTM container has complex variable logic that's become hard to maintain, Adslytics can refactor it into clean, scalable implementations. Get in touch to find out more.
Need expert tracking setup?
Our Google Tag Manager experts have delivered 500+ tracking setups with a 98% success rate.
Get a Free Consultation →