Skip to content

Commit 03d7aff

Browse files
fix: Update Rokt Click ID (#1008)
1 parent bff189d commit 03d7aff

File tree

3 files changed

+91
-12
lines changed

3 files changed

+91
-12
lines changed

src/integrationCapture.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,17 @@ const integrationMapping: IntegrationIdMapping = {
105105

106106
// Rokt
107107
// https://docs.rokt.com/developers/integration-guides/web/advanced/rokt-id-tag/
108+
// https://go.mparticle.com/work/SQDSDKS-7167
108109
rtid: {
109110
mappedKey: 'passbackconversiontrackingid',
110111
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
111112
moduleId: 1277,
112113
},
114+
rclid: {
115+
mappedKey: 'passbackconversiontrackingid',
116+
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
117+
moduleId: 1277,
118+
},
113119
RoktTransactionId: {
114120
mappedKey: 'passbackconversiontrackingid',
115121
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
@@ -158,27 +164,41 @@ export default class IntegrationCapture {
158164
const cookies = this.captureCookies() || {};
159165
const localStorage = this.captureLocalStorage() || {};
160166

167+
// Facebook Rules
161168
// Exclude _fbc if fbclid is present
162169
// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc#retrieve-from-fbclid-url-query-parameter
163170
if (queryParams['fbclid'] && cookies['_fbc']) {
164171
delete cookies['_fbc'];
165172
}
166173

167-
// If both rtid and RoktTransactionId are present, prioritize rtid
174+
// ROKT Rules
175+
// If both rtid or rclid and RoktTransactionId are present, prioritize rtid/rclid
168176
// If RoktTransactionId is present in both cookies and localStorage,
169177
// prioritize localStorage
170-
if (queryParams['rtid'] && localStorage['RoktTransactionId'] && cookies['RoktTransactionId']) {
171-
delete localStorage['RoktTransactionId'];
172-
delete cookies['RoktTransactionId'];
173-
} else if (queryParams['rtid'] && localStorage['RoktTransactionId']) {
174-
delete localStorage['RoktTransactionId'];
175-
} else if (queryParams['rtid'] && cookies['RoktTransactionId']) {
176-
delete cookies['RoktTransactionId'];
177-
} else if (localStorage['RoktTransactionId'] && cookies['RoktTransactionId']) {
178+
const hasQueryParamId = queryParams['rtid'] || queryParams['rclid'];
179+
const hasLocalStorageId = localStorage['RoktTransactionId'];
180+
const hasCookieId = cookies['RoktTransactionId'];
181+
182+
if (hasQueryParamId) {
183+
// Query param takes precedence, remove both localStorage and cookie if present
184+
if (hasLocalStorageId) {
185+
delete localStorage['RoktTransactionId'];
186+
}
187+
if (hasCookieId) {
188+
delete cookies['RoktTransactionId'];
189+
}
190+
} else if (hasLocalStorageId && hasCookieId) {
191+
// No query param, but both localStorage and cookie exist
192+
// localStorage takes precedence over cookie
178193
delete cookies['RoktTransactionId'];
179194
}
180195

181-
this.clickIds = { ...this.clickIds, ...queryParams, ...localStorage, ...cookies };
196+
this.clickIds = {
197+
...this.clickIds,
198+
...queryParams,
199+
...localStorage,
200+
...cookies
201+
};
182202
}
183203

184204
/**

test/jest/integration-capture.spec.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ describe('Integration Capture', () => {
3434
it('should initialize with a filtered list of integration attribute mappings', () => {
3535
const integrationCapture = new IntegrationCapture();
3636
const mappings = integrationCapture.filteredIntegrationAttributeMappings;
37-
expect(Object.keys(mappings)).toEqual(['rtid', 'RoktTransactionId']);
37+
expect(Object.keys(mappings)).toEqual([
38+
'rtid',
39+
'rclid',
40+
'RoktTransactionId'
41+
]);
3842
});
3943
});
4044

@@ -80,6 +84,7 @@ describe('Integration Capture', () => {
8084
'gbraid=67890',
8185
'wbraid=09876',
8286
'rtid=84324',
87+
'rclid=7183717',
8388
'ScCid=1234'
8489
].join('&');
8590

@@ -102,6 +107,7 @@ describe('Integration Capture', () => {
102107
gclid: '54321',
103108
gbraid: '67890',
104109
rtid: '84324',
110+
rclid: '7183717',
105111
wbraid: '09876',
106112
ScCid:'1234'
107113
});
@@ -241,6 +247,20 @@ describe('Integration Capture', () => {
241247
});
242248
});
243249

250+
it('should capture rclid via url param', () => {
251+
const url = new URL('https://www.example.com/?rclid=7183717');
252+
253+
window.location.href = url.href;
254+
window.location.search = url.search;
255+
256+
const integrationCapture = new IntegrationCapture();
257+
integrationCapture.capture();
258+
259+
expect(integrationCapture.clickIds).toEqual({
260+
rclid: '7183717',
261+
});
262+
});
263+
244264
it('should capture RoktTransactionId via cookies', () => {
245265
window.document.cookie = 'RoktTransactionId=12345';
246266

@@ -293,6 +313,24 @@ describe('Integration Capture', () => {
293313
});
294314
});
295315

316+
it('should prioritize rclid over RoktTransactionId via cookies', () => {
317+
jest.spyOn(Date, 'now').mockImplementation(() => 42);
318+
319+
const url = new URL('https://www.example.com/?rclid=7183717');
320+
321+
window.document.cookie = 'RoktTransactionId=12345';
322+
323+
window.location.href = url.href;
324+
window.location.search = url.search;
325+
326+
const integrationCapture = new IntegrationCapture();
327+
integrationCapture.capture();
328+
329+
expect(integrationCapture.clickIds).toEqual({
330+
rclid: '7183717',
331+
});
332+
});
333+
296334
it('should prioritize rtid over RoktTransactionId via local storage', () => {
297335
jest.spyOn(Date, 'now').mockImplementation(() => 42);
298336

@@ -311,6 +349,24 @@ describe('Integration Capture', () => {
311349
});
312350
});
313351

352+
it('should prioritize rclid over RoktTransactionId via local storage', () => {
353+
jest.spyOn(Date, 'now').mockImplementation(() => 42);
354+
355+
const url = new URL('https://www.example.com/?rclid=7183717');
356+
357+
window.location.href = url.href;
358+
window.location.search = url.search;
359+
360+
localStorage.setItem('RoktTransactionId', '12345');
361+
362+
const integrationCapture = new IntegrationCapture();
363+
integrationCapture.capture();
364+
365+
expect(integrationCapture.clickIds).toEqual({
366+
rclid: '7183717',
367+
});
368+
});
369+
314370
it('should prioritize local storage over cookies', () => {
315371
jest.spyOn(Date, 'now').mockImplementation(() => 42);
316372

@@ -356,7 +412,7 @@ describe('Integration Capture', () => {
356412
jest.spyOn(Date, 'now').mockImplementation(() => 42);
357413

358414
const url = new URL(
359-
'https://www.example.com/?ttclid=12345&fbclid=67890&gclid=54321'
415+
'https://www.example.com/?ttclid=12345&fbclid=67890&gclid=54321&rclid=7183717&rtid=54321'
360416
);
361417

362418
window.location.href = url.href;
@@ -369,6 +425,8 @@ describe('Integration Capture', () => {
369425
fbclid: 'fb.2.42.67890',
370426
gclid: '54321',
371427
ttclid: '12345',
428+
rclid: '7183717',
429+
rtid: '54321',
372430
});
373431
});
374432

test/src/tests-integration-capture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('Integration Capture', () => {
5050
gclid: '234',
5151
gbraid: '6574',
5252
rtid: '45670808',
53+
rclid: '7183717',
5354
wbraid: '1234111',
5455
ScCid: '1234',
5556
});

0 commit comments

Comments
 (0)