Skip to content

Add analytics: GA4 + Google Ads click-ID tracking - #133

Merged
Tom Tang (qwerzl) merged 3 commits into
mainfrom
add-click-id-tracking
Aug 13, 2026
Merged

Add analytics: GA4 + Google Ads click-ID tracking#133
Tom Tang (qwerzl) merged 3 commits into
mainfrom
add-click-id-tracking

Conversation

@qwerzl

@qwerzl Tom Tang (qwerzl) commented Aug 13, 2026

Copy link
Copy Markdown
Member

Adds two analytics/attribution pieces to the docs.

1. Google Analytics / Google tag — docs.base.json

Registers Google tag ID GT-TXXP8686 via Mintlify's native GA4 integration (integrations.ga4.measurementId) rather than pasting the raw gtag.js snippet. The native path tracks page views correctly across Mintlify's client-side SPA navigation — a raw snippet would only fire page_view on the initial hard load. (Mintlify GA4 docs)

Note on the GT- prefix: this is a unified Google tag, not a G- GA4 measurement ID. Mintlify's docs.json schema requires the ID match ^G (start with G), which GT-TXXP8686 satisfies, and gtag.js loads GT- tags with the identical ?id= loader + gtag('config', ...) mechanism — so the native integration works.

Config lives in docs.base.json (the source of truth); docs.json is generated from it by scripts/build-nav and is gitignored.

2. Google Ads click-ID tracking — click-id-tracking.js

A Mintlify custom JS file (auto-included on every page) that captures a Google Ads click identifier from the landing URL into photon_* cookies scoped to photon.codes, so conversions can be attributed after the visitor navigates within the site.

  • Stores a single identifier — priority gclid > wbraid > gbraid, capped at 512 chars — plus a photon_ads_click_captured_at timestamp cookie.
  • Dedup: reloading the same click does not refresh its 90-day window; a genuinely new click replaces prior attribution and resets the timestamp. Stale identifiers of another type are cleaned up.
  • Includes a migration path that backfills captured_at for cookies set by the earlier version of this script.
  • Runs after the page is interactive, not literally top-of-<head> — an unavoidable Mintlify constraint. Still reads window.location.search on the initial landing load, which is all click-ID capture needs.
  • Fires on full page loads (the ad-click landing), not on client-side route changes — correct for click-ID capture, since the IDs only arrive on that first load.
  • Cookie is scoped Domain=photon.codes (docs canonical is https://photon.codes/docs), sharing it across the apex domain.

Behavior verified across 8 scenarios (first landing, reload, stale-type cleanup, new-click replacement, organic visit, migration, over-length id, encoding round-trip).

Add a Mintlify custom JS file (auto-included on every page) that reads
gclid/gbraid/wbraid from the landing URL and persists them as
photon_* cookies scoped to photon.codes for conversion attribution.
Copilot AI lite review requested due to automatic review settings August 13, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 790a70f6-b865-420d-b109-12765dd7472c

📥 Commits

Reviewing files that changed from the base of the PR and between 83b26b7 and be22241.

📒 Files selected for processing (1)
  • docs.base.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs.base.json

📝 Walkthrough

Walkthrough

The browser extracts gclid, gbraid, and wbraid from the landing URL. It stores each present value in a secure, site-wide cookie for 90 days. The documentation configuration adds a GA4 measurement ID.

Changes

Click ID tracking and GA4 configuration

Layer / File(s) Summary
Extract and persist click identifiers
click-id-tracking.js
The script URL-encodes present gclid, gbraid, and wbraid values. It stores them in photon.codes cookies with 90-day expiration, SameSite=Lax, Secure, and root-path attributes.
Configure GA4
docs.base.json
The documentation configuration adds the integrations.ga4 block with measurement ID GT-TXXP8686.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to be222

The PR adds GA4 configuration and persists advertising click IDs for attribution; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant LandingURL
  participant ClickIDScript
  participant BrowserCookie
  LandingURL->>ClickIDScript: Provide click ID parameters
  ClickIDScript->>BrowserCookie: Store encoded IDs for 90 days
Loading

Poem

I’m a rabbit tracking clicks in the night,
gclid and friends tucked away just right.
Encoded and secure, for ninety days,
GA4 joins the documentation maze.
Ears up—each landing signal stays!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: adding GA4 analytics and Google Ads click-ID tracking.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-click-id-tracking

Comment @coderabbitai help to get the list of available commands.

Register measurement ID G-WDQR0KJG87 through docs.json's integrations.ga4
field rather than a raw gtag snippet, so page views are tracked correctly
across Mintlify's client-side SPA navigation.
Copilot AI review requested due to automatic review settings August 13, 2026 20:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qwerzl Tom Tang (qwerzl) changed the title Capture Google Ads click IDs into photon.codes cookies Add analytics: GA4 + Google Ads click-ID tracking Aug 13, 2026
Update the ga4 integration measurement ID from G-WDQR0KJG87 to the new
GT- Google tag. Mintlify's schema requires the ID start with 'G' (pattern
^G), which GT-TXXP8686 satisfies, and gtag.js loads GT- tags identically.
Copilot AI review requested due to automatic review settings August 13, 2026 20:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qwerzl
Tom Tang (qwerzl) merged commit d1a85fb into main Aug 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants