DEV Community

Cover image for Tracking Traffic From ChatGPT, Perplexity and Gemini in GA4 and BigQuery
Furqan Khalid
Furqan Khalid

Posted on

Tracking Traffic From ChatGPT, Perplexity and Gemini in GA4 and BigQuery

AI visibility metrics tell you how often assistants mention and cite you. Sooner or later someone asks the follow-up: does any of that turn into traffic?

Part of the answer is already in your analytics, mixed into "Referral" alongside every other website. This post separates it out:

  1. a custom channel group in GA4 for AI assistants,
  2. a BigQuery query over the GA4 export that pulls AI-referred sessions and landing pages,
  3. a join against citation data to compare "cited" with "clicked".

It also covers the large share of AI-influenced traffic you can't see this way, because that limitation should shape how you report the numbers.


How AI traffic shows up

When a user clicks a source link inside an AI answer, the visit arrives in one of three ways:

Signal Example Notes
Referrer header https://chatgpt.com/, https://www.perplexity.ai/ Most common for web clients.
UTM parameter ?utm_source=chatgpt.com ChatGPT adds this to many outbound links.
Nothing (direct) Mobile apps, privacy settings and copy-pasted URLs often strip the referrer.

Referrer hosts to match (keep this list in one place, it changes):

chatgpt.com, chat.openai.com
perplexity.ai, www.perplexity.ai
gemini.google.com
copilot.microsoft.com
claude.ai
chat.deepseek.com
Enter fullscreen mode Exit fullscreen mode

Google's AI Overviews and AI Mode clicks generally come through as ordinary Google organic traffic, so they won't appear here.

Step 1: A custom channel group in GA4

In Admin → Data display → Channel groups, copy the default group and add a channel called AI assistants with this condition:

  • Source matches regex:
^(chatgpt\.com|chat\.openai\.com|(www\.)?perplexity\.ai|gemini\.google\.com|copilot\.microsoft\.com|claude\.ai|chat\.deepseek\.com)$
Enter fullscreen mode Exit fullscreen mode

Then drag the new channel above "Referral". Channels are evaluated in order, and the first match wins, so if Referral sits above it, AI traffic is still caught by Referral.

Because the rule matches source, it catches both referrer-based and utm_source=chatgpt.com visits. Custom channel groups also apply retroactively in GA4 reports, so you get history from day one.

Step 2: Raw AI sessions from the BigQuery export

The UI is fine for trends. For landing pages, joins and custom logic, use the BigQuery export. This query finds the first page_view of each session that came from an AI assistant, using either the referrer or the UTM source:

DECLARE ai_re STRING DEFAULT
  r'(chatgpt\.com|chat\.openai\.com|perplexity\.ai|gemini\.google\.com|copilot\.microsoft\.com|claude\.ai|chat\.deepseek\.com)';

WITH pv AS (
  SELECT
    PARSE_DATE('%Y%m%d', event_date)                                   AS day,
    user_pseudo_id,
    (SELECT value.int_value    FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS session_id,
    (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location') AS page_location,
    (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_referrer') AS page_referrer,
    collected_traffic_source.manual_source                              AS utm_source,
    event_timestamp
  FROM `my-project.analytics_123456789.events_*`
  WHERE _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY))
                          AND FORMAT_DATE('%Y%m%d', CURRENT_DATE())
    AND event_name = 'page_view'
),
landing AS (
  SELECT *,
    ROW_NUMBER() OVER (PARTITION BY user_pseudo_id, session_id ORDER BY event_timestamp) AS rn
  FROM pv
)
SELECT
  day,
  COALESCE(REGEXP_EXTRACT(page_referrer, ai_re), REGEXP_EXTRACT(utm_source, ai_re)) AS assistant,
  REGEXP_REPLACE(REGEXP_EXTRACT(page_location, r'^https?://[^/]+([^?#]*)'), r'/$', '') AS landing_path,
  COUNT(*) AS sessions
FROM landing
WHERE rn = 1
  AND (REGEXP_CONTAINS(IFNULL(page_referrer, ''), ai_re)
       OR REGEXP_CONTAINS(IFNULL(utm_source, ''), ai_re))
GROUP BY day, assistant, landing_path
ORDER BY sessions DESC;
Enter fullscreen mode Exit fullscreen mode

Notes:

  • collected_traffic_source exists in exports from mid-2023 onward. For older data, rely on the referrer only.
  • REGEXP_EXTRACT returns the matched host, so www.perplexity.ai and perplexity.ai both come out as perplexity.ai.
  • Filtering on _TABLE_SUFFIX keeps the scan, and the bill, to the date range you need.
  • If you've also enabled the intraday export, events_* matches events_intraday_* tables as well, so the most recent day can be double-counted. Use events_2* to match only the daily tables.

Stacked bar and tiles of AI-referred sessions: ChatGPT 1,240, Perplexity 410, Gemini 160, Copilot 95, Claude 60

Step 3: Join "cited" with "clicked"

If you're collecting citations (see the earlier posts in this series), you have, per page, how often AI answers cited it. Now you have, per page, how many sessions AI assistants sent. Put them side by side:

WITH cited AS (
  SELECT landing_path, SUM(citations) AS citations
  FROM `my-project.ai_visibility.page_citations_28d`   -- your citation data, by path
  GROUP BY landing_path
),
clicked AS (
  SELECT landing_path, SUM(sessions) AS ai_sessions
  FROM `my-project.ai_visibility.ai_sessions_28d`      -- the Step 2 result, saved
  GROUP BY landing_path
)
SELECT
  COALESCE(c.landing_path, k.landing_path) AS landing_path,
  IFNULL(c.citations, 0)    AS citations,
  IFNULL(k.ai_sessions, 0)  AS ai_sessions,
  SAFE_DIVIDE(k.ai_sessions, c.citations) AS sessions_per_citation
FROM cited c
FULL OUTER JOIN clicked k USING (landing_path)
ORDER BY citations DESC;
Enter fullscreen mode Exit fullscreen mode

The four quadrants are the actionable part:

  • High citations, high sessions: working. Protect these pages and keep them current.
  • High citations, low sessions: the AI uses your page as a source but users don't need to click, because the answer is already complete. Common for definitions and simple facts. Consider whether the page offers a reason to visit (a tool, a template, deeper data).
  • Low citations, high sessions: traffic you can't explain from your tracked prompts. Your prompt set is missing questions people actually ask. Add them.
  • Low, low: most pages. Fine, unless they're pages you need to win.

Scatter of landing pages by AI citations vs AI sessions, split into four quadrants

What this can't measure

Be upfront with stakeholders about three blind spots:

  1. Referrer loss. App clicks and privacy settings drop referrers, and those visits land in Direct. Measured AI traffic is a floor, not a total.
  2. Zero-click influence. Many users read the AI's recommendation, then search your brand name on Google or type your URL. That shows up as branded search or direct traffic, credited to anything but AI. A rise in branded search alongside rising AI visibility is circumstantial evidence. Treat it as that.
  3. AI Overviews and AI Mode are folded into Google organic in GA4.

This is why referral traffic alone underrates AI search, and why it needs to sit next to visibility metrics rather than replace them.

One view for both

The useful report puts visibility (mentions, citations, share of voice) and outcome (AI sessions, conversions) in front of the same people, at the same cadence.

Vista AI's Brand Visibility Dashboard covers the visibility side: visibility by engine and region, share of voice against competitors, sentiment, per-query rankings and 30/90/365-day trends, with weekly email reports. It also supports multiple brands with separate query sets, which helps agencies report per client. Pair it with the GA4 channel above and you have both halves: how often AI recommends you, and how often that recommendation becomes a visit.


Top comments (0)