Skip to content

Commit 05e4013

Browse files
committed
Prevent server + client click ID mismatch
1 parent 31dbe22 commit 05e4013

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/script/src/base.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
let clientClickTracked = false;
8989
// Track click and set cookie
90-
function trackClick(identifier) {
90+
function trackClick(identifier, serverClickId) {
9191
if (clientClickTracked) return;
9292
clientClickTracked = true;
9393

@@ -104,6 +104,12 @@
104104
.then((res) => res.ok && res.json())
105105
.then((data) => {
106106
if (data) {
107+
if (serverClickId && serverClickId !== data.clickId) {
108+
console.warn(
109+
`Client-tracked click ID ${data.clickId} does not match server-tracked click ID ${queryParamClickId}, skipping...`,
110+
);
111+
return;
112+
}
107113
cookieManager.set(DUB_ID_VAR, data.clickId);
108114
// if partner data is present, set it as dub_partner_data cookie
109115
if (data.partner) {
@@ -143,7 +149,7 @@
143149

144150
// Dub Partners tracking (via query param e.g. ?via=partner_id)
145151
if (QUERY_PARAM_VALUE && SHORT_DOMAIN && shouldSetCookie()) {
146-
trackClick(QUERY_PARAM_VALUE);
152+
trackClick(QUERY_PARAM_VALUE, clickId);
147153
}
148154
}
149155

0 commit comments

Comments
 (0)