Skip to content

Dedup click-ID capture + record capture timestamp - #134

Merged
Tom Tang (qwerzl) merged 1 commit into
mainfrom
click-id-dedup
Aug 13, 2026
Merged

Dedup click-ID capture + record capture timestamp#134
Tom Tang (qwerzl) merged 1 commit into
mainfrom
click-id-dedup

Conversation

@qwerzl

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

Copy link
Copy Markdown
Member

Follow-up to #133 (merged). Upgrades click-id-tracking.js from "store every click id present" to a deduplicated, single-identifier capture with a timestamp.

Behavior

  • Stores a single identifier — priority gclid > wbraid > gbraid, capped at 512 chars — plus a photon_ads_click_captured_at cookie.
  • Dedup: reloading the same click no longer refreshes its 90-day window (the original capture time is preserved). A genuinely new click replaces prior attribution and resets the timestamp. Stale identifiers of another type are cleaned up.
  • Migration: backfills captured_at for cookies written by the previous version of the script.
  • Unchanged: still a Mintlify custom JS file auto-included on every page; cookie scoped Domain=photon.codes so it's shared across the apex domain.

Verification

Ran the actual script against a simulated cookie jar across 8 scenarios — all pass:

Scenario Result
First landing (?gclid=…) sets id + captured_at
Reload same click captured_at preserved (no refresh)
Same click, stale other-type cookie present stale id removed, timestamp kept
New click (?wbraid=…) old id cleared, new id + fresh timestamp
Organic visit (no params) existing attribution untouched
Existing id, no timestamp migration backfills captured_at
Over-length id (>512) ignored
URL-encoded value round-trips (a/b c+d)

Note: implementation uses top-level return, so it's wrapped in an IIFE; formatted to the repo's antfu ESLint style (pre-commit lint/generate/typecheck pass).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Improved click attribution tracking for supported identifiers.
    • Preserved attribution during organic visits and same-click page reloads.
    • Replaced outdated attribution when a genuinely new click is detected.
    • Ignored malformed tracking data and removed stale identifier values.
    • Added consistent expiration and size limits for stored attribution data.

Store a single click identifier (priority gclid > wbraid > gbraid, capped
at 512 chars) plus a photon_ads_click_captured_at cookie. A reload of the
same click no longer refreshes its 90-day window; a genuinely new click
replaces prior attribution and resets the timestamp. Includes a migration
path that backfills the timestamp for cookies set by the previous script.
Copilot AI lite review requested due to automatic review settings August 13, 2026 23:30

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: 96f0c1eb-d46a-4c05-a55a-34c8264868ad

📥 Commits

Reviewing files that changed from the base of the PR and between d1a85fb and 3d64343.

📒 Files selected for processing (1)
  • click-id-tracking.js
📜 Recent review details
🔇 Additional comments (4)
click-id-tracking.js (4)

1-53: LGTM!


55-73: LGTM!


75-103: LGTM!


105-113: LGTM!


📝 Walkthrough

Walkthrough

The script now validates supported click identifiers, manages attribution cookies through shared helpers, preserves same-click attribution, migrates missing timestamps, removes stale identifiers, and replaces attribution for new clicks.

Changes

Click attribution tracking

Layer / File(s) Summary
Cookie management
click-id-tracking.js
The script isolates cookie operations and applies shared encoding, deletion, 512-character, and 90-day lifetime settings.
Identifier selection
click-id-tracking.js
The script selects the first valid supported URL identifier and ignores oversized or malformed values.
Attribution state handling
click-id-tracking.js
The script preserves same-click attribution, migrates missing timestamps, removes stale identifier types, and replaces attribution for new clicks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: ⚪ Minimal · up to 3d643

This change deduplicates click-ID attribution and records its original capture time without introducing any actionable merge-blocking risk; it is merge-ready after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant ClickIdTracking
  participant CookieStore
  Browser->>ClickIdTracking: provide URL click parameters
  ClickIdTracking->>CookieStore: read existing attribution cookies
  ClickIdTracking->>CookieStore: preserve or replace attribution state
  CookieStore-->>ClickIdTracking: return updated cookie state
Loading

Possibly related PRs

  • photon-hq/docs#133: Both changes modify click-id-tracking.js to track gclid, gbraid, and wbraid with cookies.

Poem

A rabbit checks each click with care,
And stores the trail in cookie lair.
Old paths fade when new ones start,
Same clicks keep their matching chart.
Timestamps hop into place—
Clean attribution wins the race!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: deduplicated click-ID capture and capture-timestamp recording.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch click-id-dedup

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

@qwerzl
Tom Tang (qwerzl) merged commit f4ce6d6 into main Aug 13, 2026
6 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