Skip to content

Commit bbc1a63

Browse files
fix: Add Rokt Click ID for Integration Capture
1 parent 3645120 commit bbc1a63

File tree

3 files changed

+92
-61
lines changed

3 files changed

+92
-61
lines changed

src/integrationCapture.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ const integrationMapping: IntegrationIdMapping = {
9999
output: IntegrationOutputs.CUSTOM_FLAGS,
100100
},
101101

102+
// Rokt
103+
rtid: {
104+
mappedKey: 'Rokt.ClickId',
105+
output: IntegrationOutputs.CUSTOM_FLAGS,
106+
},
107+
102108
// TIKTOK
103109
ttclid: {
104110
mappedKey: 'TikTok.Callback',

test/jest/integration-capture.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import IntegrationCapture, {
33
} from '../../src/integrationCapture';
44
import { deleteAllCookies } from './utils';
55

6-
describe('Integration Capture', () => {
6+
describe.only('Integration Capture', () => {
77
describe('constructor', () => {
88
it('should initialize with clickIds as undefined', () => {
99
const integrationCapture = new IntegrationCapture();
@@ -26,6 +26,7 @@ describe('Integration Capture', () => {
2626
'gclid',
2727
'gbraid',
2828
'wbraid',
29+
'rtid',
2930
'ttclid',
3031
]);
3132
});
@@ -66,7 +67,15 @@ describe('Integration Capture', () => {
6667
it('should pass all clickIds to clickIds object', () => {
6768
jest.spyOn(Date, 'now').mockImplementation(() => 42);
6869

69-
const url = new URL('https://www.example.com/?fbclid=12345&gclid=54321&gbraid=67890&wbraid=09876');
70+
const queryParams = [
71+
'fbclid=12345',
72+
'gclid=54321',
73+
'gbraid=67890',
74+
'wbraid=09876',
75+
'rtid=84324',
76+
].join('&');
77+
78+
const url = new URL(`https://www.example.com/?${queryParams}`);
7079

7180
window.document.cookie = '_cookie1=1234';
7281
window.document.cookie = '_cookie2=39895811.9165333198';
@@ -84,6 +93,7 @@ describe('Integration Capture', () => {
8493
_fbp: '54321',
8594
gclid: '54321',
8695
gbraid: '67890',
96+
rtid: '84324',
8797
wbraid: '09876',
8898
});
8999
});
@@ -191,6 +201,22 @@ describe('Integration Capture', () => {
191201
});
192202
});
193203

204+
describe('Rokt Click Ids', () => {
205+
it('should capture Rokt click id', () => {
206+
const url = new URL('https://www.example.com/?rtid=54321');
207+
208+
window.location.href = url.href;
209+
window.location.search = url.search;
210+
211+
const integrationCapture = new IntegrationCapture();
212+
integrationCapture.capture();
213+
214+
expect(integrationCapture.clickIds).toEqual({
215+
rtid: '54321',
216+
});
217+
});
218+
});
219+
194220
});
195221

196222
describe('#captureQueryParams', () => {

test/src/tests-integration-capture.ts

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Integration Capture', () => {
4141
fbclid: '1234',
4242
gclid: '234',
4343
gbraid: '6574',
44+
rtid: '45670808',
4445
wbraid: '1234111',
4546
});
4647

@@ -71,13 +72,12 @@ describe('Integration Capture', () => {
7172
expect(testEvent.data).to.have.property('event_name', 'Test Event');
7273
expect(testEvent.data).to.have.property('custom_flags');
7374

74-
expect(testEvent.data.custom_flags).to.deep.equal({
75-
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
76-
'Facebook.BrowserId': '54321',
77-
'GoogleEnhancedConversions.Gclid': '234',
78-
'GoogleEnhancedConversions.Gbraid': '6574',
79-
'GoogleEnhancedConversions.Wbraid': '1234111',
80-
});
75+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal(`fb.1.${initialTimestamp}.1234`);
76+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
77+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
78+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
79+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
80+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
8181
});
8282

8383
it('should add captured integrations to event custom flags, prioritizing passed in custom flags', async () => {
@@ -91,17 +91,16 @@ describe('Integration Capture', () => {
9191

9292
const testEvent = findEventFromRequest(fetchMock.calls(), 'Test Event');
9393

94-
9594
expect(testEvent).to.have.property('data');
9695
expect(testEvent.data).to.have.property('event_name', 'Test Event');
9796
expect(testEvent.data).to.have.property('custom_flags');
98-
expect(testEvent.data.custom_flags).to.deep.equal({
99-
'Facebook.ClickId': 'passed-in',
100-
'Facebook.BrowserId': '54321',
101-
'GoogleEnhancedConversions.Gclid': '234',
102-
'GoogleEnhancedConversions.Gbraid': '6574',
103-
'GoogleEnhancedConversions.Wbraid': '1234111',
104-
});
97+
98+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal('passed-in');
99+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
100+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
101+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
102+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
103+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
105104
});
106105

107106
it('should add captured integrations to page view custom flags', async () => {
@@ -119,13 +118,13 @@ describe('Integration Capture', () => {
119118
expect(testEvent).to.have.property('data');
120119
expect(testEvent.data).to.have.property('screen_name', 'Test Page View');
121120
expect(testEvent.data).to.have.property('custom_flags');
122-
expect(testEvent.data.custom_flags).to.deep.equal({
123-
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
124-
'Facebook.BrowserId': '54321',
125-
'GoogleEnhancedConversions.Gclid': '234',
126-
'GoogleEnhancedConversions.Gbraid': '6574',
127-
'GoogleEnhancedConversions.Wbraid': '1234111',
128-
});
121+
122+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal(`fb.1.${initialTimestamp}.1234`);
123+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
124+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
125+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
126+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
127+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
129128
});
130129

131130
it('should add captured integrations to page view custom flags, prioritizing passed in custom flags', async () => {
@@ -141,13 +140,13 @@ describe('Integration Capture', () => {
141140
expect(testEvent).to.have.property('data');
142141
expect(testEvent.data).to.have.property('screen_name', 'Test Page View');
143142
expect(testEvent.data).to.have.property('custom_flags');
144-
expect(testEvent.data.custom_flags).to.deep.equal({
145-
'Facebook.ClickId': 'passed-in',
146-
'Facebook.BrowserId': '54321',
147-
'GoogleEnhancedConversions.Gclid': '234',
148-
'GoogleEnhancedConversions.Gbraid': '6574',
149-
'GoogleEnhancedConversions.Wbraid': '1234111',
150-
});
143+
144+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal('passed-in');
145+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
146+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
147+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
148+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
149+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
151150
});
152151

153152
it('should add captured integrations to commerce event custom flags', async () => {
@@ -178,14 +177,14 @@ describe('Integration Capture', () => {
178177

179178
expect(testEvent.data.product_action).to.have.property('action', 'purchase');
180179
expect(testEvent.data).to.have.property('custom_flags');
181-
expect(testEvent.data.custom_flags).to.deep.equal({
182-
foo: 'bar',
183-
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
184-
'Facebook.BrowserId': '54321',
185-
'GoogleEnhancedConversions.Gclid': '234',
186-
'GoogleEnhancedConversions.Gbraid': '6574',
187-
'GoogleEnhancedConversions.Wbraid': '1234111',
188-
});
180+
181+
expect(testEvent.data.custom_flags['foo'], 'Custom Flag').to.equal('bar');
182+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal(`fb.1.${initialTimestamp}.1234`);
183+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
184+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
185+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
186+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
187+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
189188
});
190189

191190
it('should add captured integrations to commerce event custom flags, prioritizing passed in flags', async () => {
@@ -217,13 +216,13 @@ describe('Integration Capture', () => {
217216

218217
expect(testEvent.data.product_action).to.have.property('action', 'purchase');
219218
expect(testEvent.data).to.have.property('custom_flags');
220-
expect(testEvent.data.custom_flags).to.deep.equal({
221-
'Facebook.ClickId': 'passed-in',
222-
'Facebook.BrowserId': '54321',
223-
'GoogleEnhancedConversions.Gclid': '234',
224-
'GoogleEnhancedConversions.Gbraid': '6574',
225-
'GoogleEnhancedConversions.Wbraid': '1234111',
226-
});
219+
220+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal('passed-in');
221+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
222+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
223+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
224+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
225+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
227226
});
228227

229228
it('should add captured integrations to commerce event custom flags', async () => {
@@ -254,14 +253,14 @@ describe('Integration Capture', () => {
254253

255254
expect(testEvent.data.product_action).to.have.property('action', 'purchase');
256255
expect(testEvent.data).to.have.property('custom_flags');
257-
expect(testEvent.data.custom_flags).to.deep.equal({
258-
foo: 'bar',
259-
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
260-
'Facebook.BrowserId': '54321',
261-
'GoogleEnhancedConversions.Gclid': '234',
262-
'GoogleEnhancedConversions.Gbraid': '6574',
263-
'GoogleEnhancedConversions.Wbraid': '1234111',
264-
});
256+
257+
expect(testEvent.data.custom_flags['foo'], 'Custom Flag').to.equal('bar');
258+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal(`fb.1.${initialTimestamp}.1234`);
259+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
260+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
261+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
262+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
263+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
265264
});
266265

267266
it('should add captured integrations to commerce event custom flags, prioritizing passed in flags', async () => {
@@ -293,13 +292,13 @@ describe('Integration Capture', () => {
293292

294293
expect(testEvent.data.product_action).to.have.property('action', 'purchase');
295294
expect(testEvent.data).to.have.property('custom_flags');
296-
expect(testEvent.data.custom_flags).to.deep.equal({
297-
'Facebook.ClickId': 'passed-in',
298-
'Facebook.BrowserId': '54321',
299-
'GoogleEnhancedConversions.Gclid': '234',
300-
'GoogleEnhancedConversions.Gbraid': '6574',
301-
'GoogleEnhancedConversions.Wbraid': '1234111',
302-
});
295+
296+
expect(testEvent.data.custom_flags['Facebook.ClickId'], 'Facebook Click Id').to.equal('passed-in');
297+
expect(testEvent.data.custom_flags['Facebook.BrowserId'], 'Facebook Browser Id').to.equal('54321');
298+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gclid'], 'Google Enhanced Conversions Gclid').to.equal('234');
299+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
300+
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
301+
expect(testEvent.data.custom_flags['Rokt.ClickId'], 'Rokt Click Id').to.equal('45670808');
303302
});
304303

305304
it('should add captured integrations to batch partner identities', async () => {

0 commit comments

Comments
 (0)