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
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-inPage Pathvariable, enabled under Variables → Configure.)- Go to Variables in the left sidebar, then under User-Defined Variables click New.
- Click the variable-type box and choose URL.
- 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.
- In the Query Key field that appears, type
path, the name of the parameter (the part before=), not its value. - Name it something clear at the top like
URL - path param, then Save.
Now the variable returns
/pricingwhenever the URL is?path=/pricing, ready to drop into your trigger condition below.Create the trigger
Navigation here changes the URL without a reload, so use History Change → Some History Changes, fire when yourURL - path paramvariable equals/pricing. A normal multi-page site would use a Page View trigger withPage Pathequals/pricing.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.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
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