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

Lesson 4 of 15

Page-Path Triggers

① Connect your GTM container

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

Advanced: use a specific environment

Most tags shouldn't fire everywhere, you scope them to the pages that matter with a Page Path condition. Page Path is the part of the URL after the domain, so a trigger can say "only on /pricing".

This sandbox changes the path without a full reload, so you'll use a History Change trigger here; on a normal multi-page site you'd use a Page View trigger with the same Page Path condition.

Goal

Fire a tag on a single path (/pricing) and keep it silent everywhere else.

Build it in GTM

  1. Make the variable that reads the path

    This sandbox stores the simulated path in a ?path= query parameter, so you'll build a small URL variable to pull that value out. (On a real multi-page site the path is genuinely in the URL, so you'd skip this and use the built-in Page Path variable, enabled under Variables → Configure.)

    1. Go to Variables in the left sidebar, then under User-Defined Variables click New.
    2. Click the variable-type box and choose URL.
    3. Set Component Type to Query. This tells GTM to return the value of a single query parameter rather than the whole URL or just the path.
    4. In the Query Key field that appears, type path, the name of the parameter (the part before =), not its value.
    5. Name it something clear at the top like URL - path param, then Save.

    Now the variable returns /pricing whenever the URL is ?path=/pricing, ready to drop into your trigger condition below.

  2. Create the trigger

    Navigation here changes the URL without a reload, so use History ChangeSome History Changes, fire when your URL - path param variable equals /pricing. A normal multi-page site would use a Page View trigger with Page Path equals /pricing.
  3. Tag: Custom HTML - Test

    New tag → Custom HTML. Paste <script></script> (fires but does nothing), and set this trigger as its firing trigger.

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

Each navigation adds a History event (gtm.historyChange). On /pricing your tag appears under Tags Fired; on /home and /blog it stays under Tags Not Fired.

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