Lookup Tables and RegEx Tables in GTM: Simplify Complex Setups | Adslytics

Google Tag Manager Setup & Audit How-To

Lookup Tables and RegEx Tables in GTM: Simplify Complex Setups

By Muhammad Farooq · January 20, 2026 · 6 min read
Lookup Tables and RegEx Tables in GTM: Simplify Complex Setups

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

  1. Go to Variables → New → Lookup Table
  2. Set the Input Variable to the value you want to map from (e.g. {{Page Path}})
  3. Add rows: Input → Output (e.g. /contact/Contact Page)
  4. 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

  1. Go to Variables → New → RegEx Table
  2. Set the Input Variable
  3. Add rows: each Input is a regex pattern, Output is the returned value
  4. Check Ignore Case if capitalisation might vary
  5. 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
  • ^/pricingPricing
  • ^/contactContact

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}}:

  • LiveG-PROD123456
  • NowG-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

ScenarioBest Choice
Finite list of known exact valuesLookup Table
URL patterns, varying stringsRegEx Table
Conditional logic with multiple inputsCustom JavaScript
Value needs computation or transformationCustom 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 →
← Back to Blog
Muhammad Farooq

Author

Muhammad Farooq GTM & Analytics Expert · Adslytics Founder

Tracking specialist with 10+ years of experience in Google Tag Manager, GA4, Server-Side Tracking, and Google Ads. Founder of Adslytics — a dedicated analytics agency with a 98% success rate across 232+ projects on Upwork.

Top Rated Plus LinkedIn Visit the author's profile →