Label AI Referrals in GA4 with GTM (Custom Dimension)
Build a GTM RegEx Table variable that labels ChatGPT, Claude, Perplexity and Gemini visits, send it as a GA4 event-scoped dimension, then test it.
- gtm
- ga4
- ai-referrals
- custom-dimension
- regex
To label AI referrals in GA4, build a GTM AI referrer custom dimension: a RegEx Table variable on the built-in HTTP Referrer that maps hostnames such as chatgpt.com and claude.ai to an assistant name, then send it as an event parameter registered as an event-scoped custom dimension. It cannot label visits that arrive without a referrer, and Google says a new dimension needs 24-48 hours before it reports.
As of 1 Nov 2026.
What can a GTM variable catch, and what will it miss?
A GTM variable can label an AI visit only when the browser sends a referrer. Tag Manager's HTTP Referrer variable holds "the URL of the previous page that the person visited" (Google Tag Manager Help, checked 1 Nov 2026). If the visit has no previous page on record, the variable has nothing to match and GA4 files the visit under Direct.
Here is the reader's problem as a report row. The example below is invented and uses no real data.
| Landing session | Referrer the browser sent | GA4 default view | After the GTM label |
|---|---|---|---|
| Example A | https://chatgpt.com/ |
chatgpt.com / referral | ChatGPT |
| Example B | https://claude.ai/ |
claude.ai / referral | Claude |
| Example C | none (app opens the link) | (direct) / (none) | still (direct) / (none) |
Row C is the limit. Third-party tests recorded in our dataset report that the ChatGPT mobile app sent no referrer and that the Perplexity desktop app sent none (both Ahrefs, May 2025). Those are reports, not vendor statements. The mechanics of that gap are in why AI traffic shows as Direct.
So which hostnames are worth putting in the table, and how far can you trust each one?
Which referrer hostnames belong in the table, and how sure are we?
The AnswerTraffic referrer dataset, version 1.2.0 (last verified 30 Oct 2026), holds 24 rows. Only 9 carry a test; 15 are unverified. Two rows, bing.com and google.com, are ambiguous and left out of the generated table, which leaves 22 usable rows that map to 14 assistant labels.
Method box. Source: the AI referrer dataset, file ai-referrers.json, version 1.2.0, verified 30 Oct 2026. Counted: declared rows against actual rows (24 and 24), then evidence_type and referrer_behavior per row. Ambiguous rows removed before generating patterns. Limits: the dataset compiles third-party tests (Ahrefs, May 2025, and others) and tool filter lists. Every evidenced row is a third_party_test. No row is backed by vendor documentation, and no row was tested by us in a browser.
Of the 22 usable rows, 7 are third-party tested and 15 are unverified. The tested hostnames are chatgpt.com, perplexity.ai, claude.ai, gemini.google.com, copilot.microsoft.com, www.meta.ai and chat.mistral.ai.
| Hostname | Output label | Referrer behavior | Evidence | Evidence date |
|---|---|---|---|---|
| chatgpt.com | ChatGPT | partial | third_party_test | 2025-05 |
| perplexity.ai | Perplexity | sent | third_party_test | 2025-05 |
| claude.ai | Claude | sent | third_party_test | 2025-05 |
| gemini.google.com | Gemini | partial | third_party_test | 2025-05 |
| copilot.microsoft.com | Microsoft Copilot | partial | third_party_test | 2025-05 |
| www.meta.ai | Meta AI | sent | third_party_test | 2025-05 |
| chat.mistral.ai | Le Chat (Mistral) | sent | third_party_test | 2025-05 |
| chat.openai.com | ChatGPT | unknown | unverified | none |
| www.perplexity.ai | Perplexity | unknown | unverified | none |
| edgeservices.bing.com, copilot.com, copilot.cloud.microsoft | Microsoft Copilot | unknown | unverified | none |
| grok.x.com, grok.com | Grok | unknown | unverified | none |
| chat.deepseek.com, deepseek.com | DeepSeek | unknown | unverified | none |
| meta.ai | Meta AI | unknown | unverified | none |
| you.com | You.com | unknown | unverified | none |
| iask.ai | iAsk | unknown | unverified | none |
| phind.com | Phind | unknown | unverified | none |
| duck.ai | Duck.ai | unknown | unverified | none |
| chat.qwen.ai | Qwen | unknown | unverified | none |
"Partial" means the test saw a referrer on some surfaces only. For chatgpt.com the dataset says the mobile app "was reported to send no referrer." The bing.com row is excluded because, in the dataset's words, it "is also the referrer of ordinary Bing search, so it cannot be separated by hostname."
On this site, the check had nothing to add. Our server data for 19 to 29 Oct 2026 holds 154 pageviews, and the external referrer hosts were google.com, cn.bing.com and hkgprod.akcentral.com. No assistant hostname appeared, so this site offers no confirmation of any row. Treat the 15 unverified rows as guesses that cost nothing to keep, and watch your own reports to promote them.
Next question: how do those rows become a variable?
How do I build the RegEx Table variable in GTM?
A GTM RegEx Table takes an input variable, compares it with each Pattern row, and returns the Output of the first match. Google documents that "RegEx Table lookups run from the top of the list to the bottom" (Google Tag Manager Help, checked 1 Nov 2026). Use the HTTP Referrer as input and change one default so hostname patterns match inside a full URL.
These steps follow Google's documentation. They were not run in a GTM test container for this article, so treat the menu wording as a guide and confirm it in your workspace.
- In your container, make sure the built-in HTTP Referrer variable is on. Google says Tag Manager creates an instance automatically, and you can add more.
- Open Variables, then New, and choose the RegEx Table type. Name it
AI referrer label. - Set the input variable to HTTP Referrer.
- Add one row per hostname: Pattern on the left, Output on the right.
- Under Advanced Settings, turn Full Matches Only off. Google documents that with it off, "patterns will match when they are found anywhere in the input", and that by default patterns "must match the full input string and are case insensitive." The input is a full URL with a path, so a full-match pattern for a bare hostname would never fire.
- Leave Ignore Case on. Optionally tick Set Default Value to choose what the variable returns when nothing matches; Google describes it as "an output value for when a match is not found."
Rows for the seven tested hostnames, generated from the dataset. The patterns carry their own start anchor and a boundary after the hostname, so notchatgpt.com or a hostname inside a query string cannot match:
Pattern Output
^https?://chatgpt\.com(:[0-9]+)?(/|$) ChatGPT
^https?://perplexity\.ai(:[0-9]+)?(/|$) Perplexity
^https?://claude\.ai(:[0-9]+)?(/|$) Claude
^https?://gemini\.google\.com(:[0-9]+)?(/|$) Gemini
^https?://copilot\.microsoft\.com(:[0-9]+)?(/|$) Microsoft Copilot
^https?://www\.meta\.ai(:[0-9]+)?(/|$) Meta AI
^https?://chat\.mistral\.ai(:[0-9]+)?(/|$) Le Chat (Mistral)
Add the unverified hostnames from the table above in the same shape, below these seven. Order does not matter for these patterns because no two can match the same URL, but keep the tested rows on top so you can see them.
The variable exists. How does its value reach GA4?
How do I send the GTM AI referrer custom dimension to GA4?
GA4 reports on a custom event parameter only after you register it as an event-scoped custom dimension. Google defines these as dimensions that "enable you to report on custom event parameters" (Analytics Help, checked 1 Nov 2026). Pass the variable as an event parameter in GTM, then create the dimension in GA4 Admin.
- In GTM, add an event parameter named
ai_assistantto your GA4 tag, with the value{{AI referrer label}}. Tag Manager documents reusing a parameter across tags with a Google tag: Event settings variable. The exact tag screens were not read for this article, so follow your tag type's own parameter table. - In GA4, open Admin and then Custom definitions. Google's page says this screen also shows how close you are to the limit.
- Create a custom dimension with event scope and the parameter name
ai_assistant. Field labels here are not quoted from Google's page, so check them in your interface. - Wait. Google says that "after 24-48 hours, you can start to report on and advertise with the custom dimension or metric."
Google lists these limits:
| Scope | Standard property | 360 property |
|---|---|---|
| User-scoped | 25 | 100 |
| Event-scoped | 50 | 125 |
| Item-scoped | 10 | 25 |
Before trusting any report, how do you check the variable does what you think?
How do I test that the label works?
Test in GTM Preview first, then GA4 DebugView. Open Preview, load your site by clicking from a page on a listed hostname, and read the variable's value in the Variables tab. Then confirm the ai_assistant parameter on the event in DebugView. No GTM Preview run or DebugView session was performed for this article, so there is no recorded output here.
| Step | What to look at | Pass when |
|---|---|---|
| Preview, Variables tab | AI referrer label on the landing page |
Shows the assistant name, not the default |
| Preview, wrong host | A visit from a page not in the table | Shows the default or nothing |
| DebugView | Event parameters on the landing event | ai_assistant is present with the same value |
| Reports, after 24-48 hours | The custom dimension on a table of events | Rows labelled by assistant |
A spoofed referrer proves only that your pattern matches. Only a real click from the assistant proves that it sends a referrer at all. The referrer checker on this site shows what a browser reports for a click, which separates a pattern problem from a missing referrer.
When the test fails, which cause should you check first?
What goes wrong, and what should I check first?
Three causes are worth checking, in this order: the referrer is empty, GA4 treats the domain as an unwanted referral, or the pattern does not match the hostname sent. Each has a source you can read.
| Symptom | Likely cause | Check | Source |
|---|---|---|---|
| Variable empty or default | No referrer sent (apps, privacy settings) | Preview shows no HTTP Referrer value | Dataset notes for ChatGPT mobile and Perplexity desktop, Ahrefs, May 2025 (reported) |
| Referrer present, GA4 shows no source | Domain is on the unwanted referrals list | Data stream settings, List unwanted referrals | Analytics Help, checked 1 Nov 2026 |
| Referrer present, variable default | Pattern or Full Matches Only mismatch | Preview input value against the pattern | Tag Manager Help, checked 1 Nov 2026 |
| Dimension missing in reports | Under 24-48 hours since creation | Wait, then reload the report | Analytics Help, checked 1 Nov 2026 |
| Hostname missing from table | Assistant uses a host not in the dataset | Compare with dataset version 1.2.0, verified 30 Oct 2026 | AnswerTraffic dataset |
On unwanted referrals, Google says you can configure a maximum of 50 per data stream, that conditions are evaluated using OR logic, and that matching events carry a parameter indicating "that the referrer should not be displayed" (Analytics Help, checked 1 Nov 2026). Review that list for any assistant hostname you added by hand.
Visits with no referrer stay in Direct whatever the variable does. Finding ChatGPT traffic in Direct covers that part.
Takeaway: ship the seven tested patterns first, and read your own reports for 24-48 hours before promoting any of the 15 unverified ones. Open the AI referrer dataset to see the evidence date behind each pattern before you add it.
Common follow-up questions
Should I use a Lookup Table or a RegEx Table variable for AI referrers?
Use a RegEx Table. Google describes a Lookup Table as mapping a variable from a two-column table of "equals" matches, and a RegEx Table as similar "with the addition of regular expression patterns." The HTTP Referrer is a full URL with a path, so an equals match on a hostname fails unless you extract the host first.
Why is my GTM AI referrer variable empty or undefined?
Either the browser sent no referrer, or no pattern matched and no default is set. Open Preview and read the HTTP Referrer value on the landing page. If it is blank, no variable can recover the visit. If it holds a URL, compare it with your patterns and the Full Matches Only setting.
Do GA4 custom dimensions apply to past data, such as old AI referrals?
Google's custom dimensions page, checked 1 Nov 2026, does not say. It states that reporting starts 24-48 hours after you create a dimension. Plan on labels for new events only, and do not rely on a vendor blog's claim either way until Google documents it.
Can I reuse the variable for a GA4 custom channel group?
The channel-group route is covered in the GA4 AI Assistants channel group guide and the GA4 setup guide. This article covers only the event-scoped custom dimension, which you can use in GA4 reports and explorations once the 24-48 hour wait has passed.
Sources
- Google Tag Manager Help: Variables of type (variable types for web), https://support.google.com/tagmanager/answer/7683362, Last checked: 1 November 2026
- Analytics Help: Custom dimensions and metrics, https://support.google.com/analytics/answer/14240153, Last checked: 1 November 2026
- Analytics Help: Identify unwanted referrals, https://support.google.com/analytics/answer/10327750, Last checked: 1 November 2026
- AnswerTraffic AI referrer dataset, https://answertraffic.com/data/ai-referrers.json, Last checked: 1 November 2026
Checked 1 November 2026.