Most GA4 audits turn up the same handful of problems. Each one has a fix that's easy to describe and fiddly to build, so it gets rebuilt from scratch in every container. These five templates package those fixes so anyone can add them in a few minutes.
They're all on the Tag Manager templates page, with a download and set-up steps for each.
Why templates, not custom code.
A custom template runs in Tag Manager's sandboxed JavaScript. It can only do what its permissions allow, and Tag Manager lists those permissions before you import it. Custom HTML tags and custom JavaScript variables can do anything on the page.
That makes templates easier to review, safer to hand to a client, and easier to update. Each of these comes with its own tests, which you can run from the template editor.
1. AI Assistant Traffic.
GA4's default channel group has an AI Assistant channel, but it only covers the assistants Google recognises. The rest show up as Referral, and some app visits arrive with no referrer at all.
This variable checks the referrer, and the utm_source that ChatGPT adds to many of the links it cites. It returns the assistant's name, such as ChatGPT, Perplexity, Gemini, Copilot or Claude, ready to send to GA4 as a custom dimension.
Background: how to track ChatGPT and other AI traffic in GA4.
2. Payment Referral Cleaner.
Customers who pay through Klarna, Clearpay, PayPal or a bank's 3-D Secure check come back from the provider's domain. GA4 then credits the sale to that referral, and paid search looks worse than it is.
The variable returns true when the visitor has come back from a payment page. Set it as the ignore_referrer parameter in your GA4 Google tag, and GA4 doesn't treat that page's referrer as a new traffic source.
It works alongside GA4's list of unwanted referrals, which you should still keep. More in Klarna, Clearpay and PayPal referrals in GA4.
3. Duplicate Purchase Guard.
A thank-you page that's refreshed, revisited or bookmarked can send the same purchase again. GA4 can remove duplicates that share a transaction ID, but ad platforms have their own rules.
The variable remembers each order ID in the browser. It returns true if the ID was first seen on an earlier page view, so a "duplicate equals false" condition on your purchase trigger stops every tag at once.
It's built so Preview mode, and several tags on different triggers, can't block the first, real purchase. More in how to fix duplicate conversions in GA4.
4. Consent Check.
In Metric Owl's scan of UK online retailers, 13 of the 25 sites that could be tested kept tracking after Reject all.
This tag is for testing, not for every visitor. Fire it in Preview after clicking Reject all, and it reports:
- a missing Consent Mode default
- a default that comes after hard-coded gtag commands
- analytics or advertising cookies present without consent
Tag Manager treats a consent type that was never set as granted. The check doesn't, so a page with no consent setup at all is caught too.
5. IP Address Redaction.
Google has told advertisers that from 11 January 2027, its ad tags in a server container can receive the visitor's full IP address. An IP address is personal data under UK and EU GDPR.
This server-side variable uses Google's own function to shorten the address. The last part of an IPv4 address becomes 0, and only the first 48 bits of an IPv6 address are kept. Use it in an Augment event transformation that sets ip_override for your advertising tags.
An option passes the full address only when advertising consent has been granted. More in server-side GTM will send full IP addresses to Google Ads.
Getting them.
Download the templates from the templates page, then import each one in Tag Manager under Templates. The page says whether each one is a variable, a tag or a server template.
They're released under the Apache License 2.0, so they're free to use on any site, including client work. The source and tests are on GitHub, and all five have been submitted to Google's Community Template Gallery.
Marc keeps the lists of AI assistants and payment domains up to date. If you'd rather have them set up and tested for you, the GA4 mini audit is the place to start.
Sources.
- Google for Developers: Custom templates guide
- Google for Developers: Sandboxed JavaScript
- Google for Developers: Community Template Gallery
- Google for Developers: Server-side tagging APIs (getAnonymizedIpAddress)
- Google for Developers: GA4 config reference (ignore_referrer)
- Google for Developers: Custom template APIs (isConsentGranted)
Checked on 6 November 2026.