Don't have one? Create one ↗
← All courses

Lesson 11 of 15

RegEx Table Variable

① Connect your GTM container

Paste your container ID to load it into this page. It only ever runs here.

Advanced: use a specific environment

A Lookup Table needs an exact match for every value. But paths come in endless variations, /blog/post-1, /blog/post-2, /product/headphones, and you cannot list them all. A RegEx Table matches each input against a pattern instead of a literal, so one row can catch a whole family of URLs.

Rows are tested top to bottom and the first match wins, so order matters. A broad .* pattern matches everything, which is why it belongs last as a catch-all, otherwise it would swallow every path before the specific rows get a turn.

Goal

Build a RegEx Table on Page Path that buckets URLs into sections, with a catch-all last.

Build it in GTM

  1. Create the RegEx Table variable

    Go to Variables → New and choose RegEx Table. Set Input Variable to {{Page Path}}.
  2. Turn on full matches only

    Open Advanced Settings and tick Full matches only. This anchors each pattern so ^/(cart|checkout)$ matches the whole path and does not partially match longer URLs.
  3. Add the specific patterns first

    Add rows in this order: ^/blog/.* to content, ^/product/.* to product, then ^/(cart|checkout)$ to purchase. Each left cell is the pattern, each right cell the output.
  4. Add the catch-all last

    As the final row add .* to other so anything unmatched still gets a value. Name it RT - page section and Save.

Debug in Tag Assistant

Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.

  1. In your GTM, click Preview.
  2. Paste the live URL above and click Connect.
  3. Interact with the live page and watch your tag fire in Tag Assistant.

What you should expect to see

In Tag Assistant's Variables tab, {{RT - page section}} resolves to content on /blog/post-1, product on /product/headphones, purchase on /cart, and other on anything else.

Verify your container

Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.

Drop your container .json here

or browse · checked in your browser, nothing is uploaded

0 of 15 lessons complete