Repository navigation
feat(traffic): only persist platform-attributable AI visits (referrer or utm), drop unknowns - #310
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the AI-traffic tracking pipeline to only record visits when they can be attributed to a specific AI platform, preventing new null-platform rows from inflating the dashboard’s “Unknown” bucket.
Changes:
- Update the tracking snippet (
t.js) to resolve a concrete platform from referrer-domain matching or knownutm_sourcevalues, and to drop unattributable events client-side. - Add a server-side guard to skip inserts when
source_platformis empty, protecting against older cached snippets that still send empty platform values. - Extend the dashboard platform label/color maps to include
labs.googleandbing.com, with a sync note to keep mappings aligned with detection.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server/src/public/t.js | Resolve and send a concrete platform (s) and avoid sending unattributable events. |
| server/src/routes/traffic.js | Skip persisting events with an empty source_platform to prevent new “Unknown” rows. |
| web/src/app/[locale]/(dashboard)/dashboard/traffic/_charts.tsx | Add labels/colors for labs.google and bing.com and document the sync requirement with detection. |
Files not reviewed (1)
- server/src/public/t.js: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+115
to
+118
| const sourcePlatform = (body.s || '').slice(0, 255); | ||
| if (!sourcePlatform) { | ||
| return res.status(204).end(); | ||
| } |
… or utm) Drop AI-traffic events that can't be attributed to a concrete platform, so the dashboard no longer shows a null-backed "Unknown" bucket. - t.js: resolve the platform from the AI referrer host (normalized to a known domain) or, when there's no referrer, from a known utm_source (chatgpt/openai, perplexity, claude, gemini, copilot). Send the resolved platform instead of the bare referrer host (which was empty for utm-detected visits, producing null rows). If nothing resolves, don't send. - traffic.js: defensively skip inserts with an empty source_platform so older cached snippets can't write null rows. - _charts.tsx: add labs.google + bing.com labels/colors; note the list must stay in sync with the t.js detection hosts. Keep "unknown" for historical pre-#288 rows. Google AI Overview clicks (referrer google.com, no utm) remain indistinguishable from organic Google and are out of scope.
gkhngyk
force-pushed
the
feature/traffic-attributable-only
branch
from
June 27, 2026 15:24
8abb62b to
1424236
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Only persist an AI-traffic event when it is attributable to a concrete AI platform, so the dashboard's null-backed "Unknown" bucket stops growing. The root cause: the snippet derived the platform from the referrer host only, so a visit detected via the
utm_sourcefallback (no AI referrer) sent an empty platform → stored asnull→ "Unknown".Changes
server/src/public/t.js— resolve a concrete platform from either signal:search.chatgpt.comcollapse to a labeled platform), orutm_source(chatgpt/openai→chatgpt.com,perplexity→perplexity.ai,claude→claude.ai,gemini→gemini.google.com,copilot→copilot.microsoft.com).The beacon now sends the resolved platform (
s: pf) instead of the bare referrer host. If neither signal resolves a platform, the snippet returns early and nothing is sent. (A bareutm_medium=aiwith no resolvable source no longer stores a null row.)server/src/routes/traffic.js— defensively skip inserts with an emptysource_platform(returns204without writing), so older cached snippets can't keep writing null rows.web/.../traffic/_charts.tsx— addlabs.google("Google Labs") andbing.com("Bing") to the label/color maps and note they must stay in sync with thet.jsdetection hosts. Keptunknownso historical pre-feat(traffic): only persist platform-attributable AI visits (referrer or utm), drop unknowns #288 null rows still render.Verification — added a standalone simulation of the
t.jsresolution covering 15 cases (referrer, www/subdomain normalization, each utm source, medium-only, non-AI utm, Google AI Overview, Bing/ck/avs organic, direct) — all pass.yarn lint/typecheck/ tests green on bothwebandserver;node --checkpasses ont.js.Related issue
Closes #288
Notes
nullrows are left in place (they keep rendering as "Unknown" until they age out of the window); only new writes are gated.t.jsis CDN + browser cached for hours, so already-installed snippets keep sending the old shape until cache expiry / a Cloudflare purge — the server-side empty-platform guard covers that window.referrer = google.comand no utm, so they're indistinguishable from organic Google and aren't captured. The optional "single shared source of truth across t.js + dashboard" was left out (the two run in different packages — server static asset vs web app); a sync comment is added in_charts.tsxinstead.Type of change
feat— New featureChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)