Skip to content

Prevent server / client click ID mismatch#60

Merged
steven-tey merged 2 commits intomainfrom
fix-attribution
May 26, 2025
Merged

Prevent server / client click ID mismatch#60
steven-tey merged 2 commits intomainfrom
fix-attribution

Conversation

@steven-tey
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented May 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
analytics-nextjs-geolocation-script ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 26, 2025 3:18pm

@steven-tey steven-tey requested review from Copilot and devkiran May 26, 2025 15:10
@steven-tey steven-tey changed the title Prevent server + client click ID mismatch Prevent server / client click ID mismatch May 26, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the click-tracking logic to detect and skip on mismatches between the click ID returned from the server and the ID provided by the client (e.g., from a query parameter).

  • Extended trackClick to accept a second parameter (serverClickId) for comparison.
  • Added a check that logs a warning and aborts cookie setting when IDs differ.
  • Updated the call site to pass through the click ID for validation.
Comments suppressed due to low confidence (3)

packages/script/src/base.js:90

  • [nitpick] The parameter name serverClickId is misleading—it's actually the expected click ID from the query parameter. Consider renaming it to expectedClickId or queryParamClickId for clarity.
function trackClick(identifier, serverClickId) {

packages/script/src/base.js:109

  • The variable queryParamClickId is undefined in this scope; it should reference the serverClickId parameter instead.
Client-tracked click ID ${data.clickId} does not match server-tracked click ID ${queryParamClickId}, skipping...

packages/script/src/base.js:152

  • The variable clickId is not defined in this scope. You likely meant to pass the parsed query parameter value (e.g., queryParamClickId).
trackClick(QUERY_PARAM_VALUE, clickId);

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a server/client click ID validation in the click tracking function to prevent mismatches between client-tracked and server-tracked IDs.

  • Modified the trackClick function to accept an additional serverClickId parameter and added a warning when the IDs do not match.
  • Updated the invocation of trackClick to include the server-side clickId in its arguments.
Comments suppressed due to low confidence (1)

packages/script/src/base.js:152

  • Ensure that 'clickId' is defined and holds the intended server-side click ID value before passing it to trackClick; an undefined clickId could cause the new validation check to be ineffective.
trackClick(QUERY_PARAM_VALUE, clickId);

@steven-tey steven-tey merged commit 2ac29d4 into main May 26, 2025
3 checks passed
@steven-tey steven-tey deleted the fix-attribution branch May 26, 2025 16:10
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