Skip to content

feat(traffic): count ChatGPT Shopping visits from feed links tagged utm_medium=feed - #1425

Merged
gkhngyk merged 1 commit into
mainfrom
feature/chatgpt-shopping-visits
Oct 23, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/chatgpt-shopping-visits

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Summary

A product URL in a feed tagged utm_source=chatgpt.com&utm_medium=feed tells a visit from a ChatGPT Shopping product card apart from one through a ChatGPT answer. Until now both were ChatGPT, and nothing read the medium.

  • Source list (ai-sources.json v3): ChatGPT gets a shopping surface, utm_medium = feed.
    • classifyAiSurface(source, medium) matches the medium exactly, in any case.
    • landingMedium(url) reads the first utm_medium of a URL.
  • /track: works out the surface from the landing URL it stores, not from a body field, so older cached snippets' visits are marked too.
  • Google Analytics (ga-sync.js): the AI report also reads sessionMedium.
    • The medium is now part of a row's key, and rows from ChatGPT with medium feed carry surface = 'shopping'.
    • After a report that returned rows, the brand's rows without a medium in the days it re-read are deleted, so those days aren't counted twice.
  • Migration 00251:
    • ai_traffic_logs.source_surface, with a check. A one-off pass marks earlier ChatGPT visits whose URL has utm_medium=feed; there are none on prod today.
    • ga_ai_traffic_stats.medium and .surface. The unique key becomes (brand_id, date, source, medium, landing_page_query), nulls not distinct.
    • ai_traffic_merged also returns surfaces, and ga_platform_value also returns a surfaces column. Platform totals are unchanged.
  • AI Traffic page:
    • "ChatGPT Shopping" is an indented row under ChatGPT in Referrals by Platform, with change, engaged and key events.
    • It is an indented bar under ChatGPT in the Platform Breakdown.
    • The Top platform card's sub-line reads "40 visits · 11 from ChatGPT Shopping".
    • The platforms export gets the same row, marked as part of ChatGPT's visits.

Checked on production, by running 00251 in a transaction that was rolled back:

  • it applies cleanly on Postgres 17;
  • for the 13 brands with traffic, ai_traffic_merged (all time) gives the same output as today apart from the new surfaces;
  • ga_platform_value gives the same 28 platform rows.

Not in this PR:

Related issue

Closes #1283

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

Deploy order

  1. Apply 00251.
  2. Deploy the server right after. The running server's GA sync upserts on the old key, which 00251 replaces, so it fails until the new server runs.
  3. Optionally run backfill-ga-ai-history.js, so GA history before the last few days gets its medium too.

How to test

  1. Open https://<a tracked site>/<product>?utm_source=chatgpt.com&utm_medium=feed from a browser.
  2. The AI Traffic page counts the visit under ChatGPT, and shows it again in the indented "ChatGPT Shopping" row.
  3. A link with only utm_source=chatgpt.com stays plain ChatGPT.

Tests cover:

  • the snippet match;
  • /track: shopping, upper case, older host, other mediums, a Perplexity feed link;
  • the GA mapping and the delete;
  • the summary's surfaces;
  • the table rows, the KPI sub-line and the platforms export.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

…tm_medium=feed

A product link in a merchant's feed tagged utm_source=chatgpt.com and
utm_medium=feed comes from a ChatGPT Shopping product card. Those visits
were counted as plain ChatGPT; now they are marked as ChatGPT Shopping and
still count under ChatGPT.

- Source list (version 3): ChatGPT gets a shopping surface, matched by the
  medium feed (classifyAiSurface, landingMedium in ai-sources.js).
- /track reads the surface from the landing URL it stores, so visits from a
  cached older snippet are marked too, and writes source_surface. The visit
  stays source_platform = 'chatgpt.com'.
- Google Analytics sync asks for sessionMedium and stores the medium and the
  surface on ga_ai_traffic_stats. The medium joins the row key; rows synced
  before have none and are replaced as their days are re-read.
- Migration 00251: source_surface on ai_traffic_logs and medium/surface on
  ga_ai_traffic_stats with checks, the new unique key, a one-off backfill
  of stored ChatGPT visits whose landing URL has utm_medium=feed, and
  ai_traffic_merged / ga_platform_value returning the visits and figures
  by surface while platform totals stay whole.
- AI Traffic page: ChatGPT Shopping shows as its own row under ChatGPT in
  Referrals by Platform (with change, engaged and key events), in the
  Platform Breakdown bars, in the Top platform card and in the platforms
  export, each marked as part of ChatGPT's visits.

Closes #1283
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 23, 2026
@gkhngyk
gkhngyk merged commit 76c8736 into main Oct 23, 2026
6 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…hors

Renumbers our migration 00251→00252: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
Renumbers our migration 00252→00253: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…heck

Renumbers our migration 00253→00254: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…rver

Renumbers our migration 00254→00255: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
Renumbers our migration 00255→00256: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
Renumbers our migration 00252→00256, as asked in review: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
Renumbers our migration 00253→00257, as asked in review: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…heck

Renumbers our migration 00254→00258, as asked in review: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…rver

Renumbers our migration 00255→00259, as asked in review: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
Renumbers our migration 00256→00260, as asked in review: main took 00251 in ansvisor#1425.
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 23, 2026
…rt-byline

Renumbers our migration 00257→00261, as asked in review: main took 00251 in ansvisor#1425.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(traffic): count ChatGPT Shopping visits from feed links tagged utm_medium=feed

1 participant