How to track AI referral traffic in GA4
Find observable AI assistant referrals in GA4, preserve traffic-source scope, and add Marshy classifications without confusing referrals with browser agents.
Dev Shah5 min read
Track observable AI referral traffic in GA4 using session-source dimensions, a maintained list of assistant referral domains, and a report of landing pages and outcomes. Keep that view separate from Marshy’s browser-agent classifications: a person can click a ChatGPT recommendation, while an agent can operate your website without an assistant referrer.
This tutorial builds two complementary reports. The first explains where a session arrived from. The second records the classification available during an instrumented browser visit.
1. Use the right acquisition scope
Open the relevant GA4 property and its Traffic acquisition report. Choose Session source / medium for the sessions you are investigating. If the report is unavailable in your navigation, use your property’s report collection or a free-form exploration with the same session-scoped dimension.
Google’s traffic-source scope documentation distinguishes first-user acquisition from session acquisition. Keep that distinction when reporting current visits: a returning customer’s first acquisition source does not necessarily describe this session.
Choose a date range and inspect the actual source values before building the filter. Your observable domains, campaign tagging, and reporting setup determine the values available in this property.
2. Filter the assistant sources you actually observe
Maintain a source list from your own report. Candidate domains to inspect include chatgpt.com, chat.openai.com, perplexity.ai, claude.ai, gemini.google.com, and copilot.microsoft.com. They are starting points for review, not a complete provider identity registry or a promise that each assistant sends a referrer.
In a free-form exploration, import Session source, Landing page + query string, and the session and outcome metrics you need. Put the source and landing page in the rows, then filter Session source against your reviewed list.
If the filter uses a full regular-expression match, an illustrative source pattern is:
^(chatgpt\.com|chat\.openai\.com|perplexity\.ai|claude\.ai|gemini\.google\.com|copilot\.microsoft\.com)$
Apply it to Session source, not a combined source/medium value. Escape the literal dots and retain exact domain matching so a lookalike name is not accidentally included. Add or remove domains based on observed values and documented campaign conventions.
Google’s Traffic acquisition reference explains the report’s dimensions and customization. UI availability depends on your property and permissions.
3. Report observable referrals with a clear denominator
A useful referral report includes source, landing page, sessions, relevant key events, and recorded revenue where ecommerce measurement is configured. Keep the combined business result as well as the source breakdown.
Call the cohort “observable assistant referrals.” Missing or suppressed source information should not be relabeled as an AI referral without another attribution method. A source filter does not establish every visit an assistant influenced.
It also does not establish who operates the session. A referred customer may browse manually, delegate a task, or switch between the two. That is where browser-session classification supplies a different observation.
4. Add a Marshy classification event separately
Install your Marshy integration and initialize your approved GA4 collection before wiring the callback. The SDK’s verdict contract supports an onVerdict callback that can replay an existing result.
This forwarding function retains human, agent, and review results. Its deduplication is bounded and local to one function instance in the document. It does not create a human event when no verdict exists.
export function createMarshyGA4Forwarder(sendEvent) {
const seen = new Set();
return detail => {
if (!detail) return;
const { verdict, kind, sessionId } = detail;
if (!['human', 'agent', 'review'].includes(verdict)) return;
if (typeof sessionId !== 'string' || !sessionId) return;
const key = JSON.stringify([sessionId, verdict, kind]);
if (seen.has(key)) return;
sendEvent('visitor_classified', {
agent_verdict: verdict,
...(typeof kind === 'string' ? { agent_kind: kind } : {}),
});
seen.add(key);
if (seen.size > 200) seen.delete(seen.values().next().value);
};
}
Once the SDK callback API and your consent-approved GA4 initialization are ready, create one forwarder and register it:
const forwardToGA4 = createMarshyGA4Forwarder((name, properties) => {
window.gtag('event', name, properties);
});
window.ResembleAgentDetection.onVerdict(forwardToGA4);
Use your actual initialization lifecycle. Do not call the callback API while the SDK is still an initialization queue. If consent is granted later, wire it then so replay can supply an existing verdict. Keep normal analytics initialization and failure handling in the application.
The SDK identifier retains its documented technical name; the integration and reporting feature are Marshy. This is a manual integration example, not a native GA4 connector.
5. Register useful event dimensions
For reporting, define event-scoped custom dimensions for agent_verdict and, if useful, agent_kind. Google’s custom-dimension instructions require appropriate property permissions and describe reporting availability after collection and configuration.
Keep the distinction between event and session scope. A classification event describes the available result; counting those events alone does not produce a session conversion rate. If you create session segments from classification events, document the segment rule and whether the result existed before the decision being analyzed.
Do not register a unique Marshy session identifier as a custom dimension merely to group these results. Google’s high-cardinality guidance explains why large numbers of dimension values can affect reports. The example uses the identifier locally for deduplication and sends only the classification fields.
6. Check the integration before interpreting revenue
Verify these cases in an owned test environment:
| Case | Expected record |
|---|---|
| Agent verdict after wiring | A visitor_classified event with agent_verdict=agent |
| Existing verdict replayed | The original classification is forwarded |
| Duplicate delivery to the same forwarder | One forwarding per deduplication key while retained |
| Review verdict | Review remains review |
| Missing or invalid verdict | No invented classification event |
| No assistant referrer | No fabricated assistant-source label |
Use GA4’s event verification views and the corresponding Marshy session to confirm delivery. The forwarding function is checked locally with simulated callback payloads; this guide does not present a live customer GA4 account or measured attribution result.
Finally, compare outcomes at the proper unit. Referral source, browser classification, and completed purchase answer different questions. Join an experiment to backend-confirmed orders and preserve classification coverage rather than inferring an uplift from two differently composed cohorts.
Continue with the AI traffic measurement guide and the agentic commerce experiment. Marshy helps investigate the browser journey behind the classification while GA4 supplies the acquisition and analytics view you configure.
Technical references checked October 8, 2026. Referral coverage depends on observable attribution and instrumentation.