How to control where the Pathmonk snippet fires using GTM
By default we recommend firing the snippet on All Pages, which is what most sites want — the engine reads the whole buying journey, so the more of it you give it, the better it works. But sometimes you need to keep Pathmonk off part of your site: a customer portal, a staging subdomain, a checkout flow, an area you don't own. Google Tag Manager handles this with exceptions and narrower triggers. This guide covers both, with recipes for the cases that come up most.
First: should you do this in GTM at all?
There are two very different ways to keep Pathmonk off a page:
| Block it in GTM | Use Pathmonk's page rules | |
|---|---|---|
| What happens | The SDK never loads. No data, no analytics, no microexperiences. | The SDK loads and keeps measuring. Microexperiences just don't display. |
| The page still feeds the engine | No — it's invisible to Pathmonk | Yes |
| Counts toward your pageviews | No | Yes |
| Best for | Pages Pathmonk shouldn't touch at all: staging, third-party tools, areas you don't own | "Don't show cards here, but keep the data": checkout, thank-you pages, support docs |
The rule of thumb: if you only want to stop cards from appearing, use Pathmonk's own include/exclude rules — see Including and excluding pages. Reach for GTM when the SDK genuinely shouldn't run at all.
This matters because blocking in GTM creates blind spots in the journey. A visitor who reads three blog posts, disappears into a blocked section, and comes back looks like two unrelated sessions to the engine. Block only what you have to.
Before you start: turn on the variables you'll need
GTM can't match on a URL it isn't reading. Most containers have these on already, but check:
- Variables → Configure (in the Built-In Variables section).
- Tick Page URL, Page Hostname, and Page Path.
What each one gives you:
| Variable | Returns | Use it for |
|---|---|---|
| Page Hostname | shop.example.com | Subdomains |
| Page Path | /account/settings | Sections and individual pages. No query string, no hash. |
| Page URL | The full URL including the query string, but not the # fragment | Query parameters, or matching on the whole thing |
Reach for Page Path by default. It's the most predictable of the three, because it doesn't change when someone arrives with a UTM string attached.
Method 1 — Exceptions ("everywhere except…")
This is the one you'll use most. Keep the tag on All Pages and add a blocking trigger for the parts you want to skip.
Step 1 — build the exception trigger.
- Triggers → New.
- Name it something readable, like
Exception – Customer portal. - Trigger type: Page View.
- Choose Some Page Views.
- Set the condition, e.g. Page Path · starts with ·
/account. - Save.
Step 2 — attach it to the Pathmonk tag.
- Open your Pathmonk tag.
- In the Triggering section, under Exceptions, click Add.
- Select the trigger you just made.
- Save, then Submit and Publish.
Exceptions win. If a page matches both the firing trigger and an exception, the tag doesn't fire. That makes exceptions safe to stack — add as many as you need, and the tag fires everywhere that matches none of them.
Two things to know about that:
- An exception only blocks a trigger on the same underlying event. Your Pathmonk tag fires on All Pages, which is a Page View event, so exceptions must also be Page View triggers. A DOM Ready or Window Loaded exception will sit there doing nothing.
- Never use the same trigger as both the firing trigger and an exception. The tag will never fire anywhere, and GTM won't warn you.
Method 2 — A narrower firing trigger ("only here")
If Pathmonk should run on a small part of the site rather than most of it, swap the trigger instead of piling up exceptions.
- Triggers → New → Page View → Some Page Views.
- Set the condition, e.g. Page Path · starts with ·
/products. - Save, then open the Pathmonk tag and replace All Pages with this trigger.
Use this sparingly. Restricting Pathmonk to a handful of pages gives the engine a narrow slice of the journey to learn from, and it will have less to work with as a result.
Common recipes
| What you want | Variable | Operator | Value |
|---|---|---|---|
| Skip a subdomain | Page Hostname | equals | app.example.com |
| Skip every staging environment | Page Hostname | contains | staging. |
| Skip a whole section | Page Path | starts with | /account |
| Skip checkout | Page Path | contains | /checkout |
| Skip one exact page | Page Path | equals | /internal/dashboard |
| Skip several sections at once | Page Path | matches RegEx | ^/(account|admin|portal)(/|$) |
| Run on the blog only | Page Path | starts with | /blog |
| Run on one subdomain only | Page Hostname | equals | www.example.com |
| Skip pages carrying a flag | Page URL | contains | nopathmonk=1 |
Matching gotchas
- Trailing slashes.
/accountand/account/are different strings. starts with/accountcatches both; equals catches only one. - Case sensitivity. GTM's string operators are case-sensitive.
/Accountwon't match/account. If your site serves mixed case, use the matches RegEx (ignore case) operator. Don't try to do it with an inline(?i)in a normal regex — GTM compiles regexes as JavaScript, which doesn't support that flag, and the condition will silently never match. - Query strings. Page Path drops them; Page URL keeps them. Ad traffic arriving with
?utm_source=…will break a Page URL equals condition. containsandstarts withare both greedier than they look. contains/blogalso matches/company/blogging-tips, and starts with/accountalso matches/accounts-payable. When a near-miss path exists on your site, use matches RegEx with an explicit boundary —^/account(/|$)catches/accountand/account/settingsbut not/accounts-payable.
Keeping Pathmonk off logged-in areas
The usual case is a marketing site with a customer portal behind it. If the portal sits on its own path or subdomain, use the recipes above — that's the easy version.
If logged-in and logged-out visitors share the same URLs, GTM needs something on the page to tell them apart:
- A data layer value. If your app already pushes something like
dataLayer.push({ userType: 'customer' })before the container loads, create a Data Layer Variable foruserTypeand build the exception on it. This is the cleanest option, but it needs a developer if the push doesn't exist yet. - A login cookie. Create a 1st-Party Cookie variable pointing at whatever cookie your platform sets for a logged-in session, and except on it. No dev work, but check the cookie is actually readable by JavaScript — an
HttpOnlycookie is invisible to GTM. - A body class or element. A Custom JavaScript variable can check for something like
document.body.classList.contains('logged-in'). Fragile if your theme changes, so keep it as a last resort.
If you only want to hide cards from logged-in visitors rather than stop measuring them, don't do any of this in GTM — Pathmonk has a setting for it. See Showing or hiding for logged-in visitors.
Things to watch
- Don't block more than you meant to. After any change, spot-check a page from each major template — homepage, blog post, product or service page, landing page — not just the one you were working on.
- Exceptions are permanent blind spots, not filters you can undo later. Pathmonk has no data for a blocked page, including for the period before you unblock it.
- Don't run two installs. If the snippet is also hardcoded in your theme, your GTM exceptions do nothing — the theme copy still loads. Pick one method. See Installing Pathmonk on your website.
- Single-page apps. A Page View trigger fires on the initial load, not on client-side route changes. On an SPA, Pathmonk loads once on the entry page and keeps running as the visitor navigates — so a path-based exception won't stop it on a route the visitor reaches without a full page load. GTM's History Change trigger does fire on those route changes, but it can't unload a script that's already running, so it doesn't solve this. If you need Pathmonk off part of an SPA, use Pathmonk's page rules instead.
- Don't block subdomains just because cards aren't showing there. Tracking already works across your subdomains — microexperiences are the part that needs the subdomain whitelisted. If the blog isn't showing cards, whitelist it rather than excluding it in GTM, or you'll throw away the data too. See Adding and whitelisting subdomains.
If the tag looks right in Preview but Pathmonk still isn't connecting on the live site, work through Is Pathmonk not connecting to your website?.
