Skip to content

Commit 839aa27

Browse files
gh-mmurphrmi22186
authored andcommitted
feat: Add collection of Snap cookie1 (#1118)
1 parent f8036f1 commit 839aa27

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

src/integrationCapture.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ const integrationMappingExternal: IntegrationIdMapping = {
120120
mappedKey: 'SnapchatConversions.ClickId',
121121
output: IntegrationOutputs.CUSTOM_FLAGS,
122122
},
123+
// Snapchat
124+
// https://developers.snap.com/api/marketing-api/Conversions-API/UsingTheAPI#sending-click-id
125+
_scid: {
126+
mappedKey: 'SnapchatConversions.Cookie1',
127+
output: IntegrationOutputs.CUSTOM_FLAGS,
128+
},
123129
};
124130

125131
const integrationMappingRokt: IntegrationIdMapping = {

test/jest/integration-capture.spec.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ describe('Integration Capture', () => {
2727
'gbraid',
2828
'wbraid',
2929
'ttclid',
30-
'ScCid'
30+
'ScCid',
31+
'_scid'
3132
]);
3233
});
3334

@@ -55,6 +56,7 @@ describe('Integration Capture', () => {
5556
'wbraid',
5657
'ttclid',
5758
'ScCid',
59+
'_scid',
5860
];
5961
for (const key of excludedKeys) {
6062
expect(mappings).not.toHaveProperty(key);
@@ -273,6 +275,42 @@ describe('Integration Capture', () => {
273275
ScCid: '1234',
274276
});
275277
});
278+
279+
it('should capture _scid from cookies', () => {
280+
const url = new URL('https://www.example.com/');
281+
282+
window.document.cookie = '_scid=cookie1-from-cookie';
283+
window.document.cookie = '_cookie1=4567';
284+
window.document.cookie = 'baz=qux';
285+
286+
window.location.href = url.href;
287+
window.location.search = url.search;
288+
289+
const integrationCapture = new IntegrationCapture('all');
290+
integrationCapture.capture();
291+
292+
expect(integrationCapture.clickIds).toEqual({
293+
_scid: 'cookie1-from-cookie',
294+
});
295+
});
296+
297+
it('should capture both ScCid from query params and _scid from cookies', () => {
298+
const url = new URL('https://www.example.com/?ScCid=4567');
299+
300+
window.document.cookie = '_scid=cookie1-from-cookie';
301+
window.document.cookie = '_cookie1=334455';
302+
303+
window.location.href = url.href;
304+
window.location.search = url.search;
305+
306+
const integrationCapture = new IntegrationCapture('all');
307+
integrationCapture.capture();
308+
309+
expect(integrationCapture.clickIds).toEqual({
310+
ScCid: '4567',
311+
_scid: 'cookie1-from-cookie',
312+
});
313+
});
276314
});
277315

278316
describe('Facebook Click Ids', () => {
@@ -611,6 +649,19 @@ describe('Integration Capture', () => {
611649
});
612650
});
613651

652+
it('should capture _scid from cookies', () => {
653+
window.document.cookie = '_cookie1=4567';
654+
window.document.cookie = '_scid=cookie1-from-cookie';
655+
window.document.cookie = 'baz=qux';
656+
657+
const integrationCapture = new IntegrationCapture('all');
658+
const clickIds = integrationCapture.captureCookies();
659+
660+
expect(clickIds).toEqual({
661+
_scid: 'cookie1-from-cookie',
662+
});
663+
});
664+
614665
it('should NOT capture cookies if they are not mapped', () => {
615666
window.document.cookie = '_cookie1=1234';
616667
window.document.cookie = '_cookie2=39895811.9165333198';
@@ -665,6 +716,8 @@ describe('Integration Capture', () => {
665716
_ttp: '0823422223.23234',
666717
ttclid: '12345',
667718
gclid: '123233.23131',
719+
ScCid: '456789',
720+
_scid: 'cookie1-value',
668721
invalidId: '12345',
669722
};
670723

@@ -675,6 +728,8 @@ describe('Integration Capture', () => {
675728
'Facebook.BrowserId': '54321',
676729
'TikTok.Callback': '12345',
677730
'GoogleEnhancedConversions.Gclid': '123233.23131',
731+
'SnapchatConversions.ClickId': '456789',
732+
'SnapchatConversions.Cookie1': 'cookie1-value',
678733
});
679734
});
680735
});

test/src/tests-integration-capture.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('Integration Capture', () => {
4545
window.document.cookie = '_fbp=54321';
4646
window.document.cookie = 'baz=qux';
4747
window.document.cookie = '_ttp=45670808';
48+
window.document.cookie = '_scid=cookie1-value';
4849
mParticle.init(apiKey, window.mParticle.config);
4950
await waitForCondition(hasIdentifyReturned);
5051
const integrationCapture = window.mParticle.getInstance()._IntegrationCapture;
@@ -89,6 +90,7 @@ describe('Integration Capture', () => {
8990
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
9091
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
9192
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
93+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
9294
});
9395

9496
it('should add captured integrations to event custom flags, prioritizing passed in custom flags', async () => {
@@ -112,6 +114,7 @@ describe('Integration Capture', () => {
112114
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
113115
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
114116
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
117+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
115118
});
116119

117120
it('should add captured integrations to page view custom flags', async () => {
@@ -136,6 +139,7 @@ describe('Integration Capture', () => {
136139
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
137140
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
138141
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
142+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
139143
});
140144

141145
it('should add captured integrations to page view custom flags, prioritizing passed in custom flags', async () => {
@@ -159,6 +163,7 @@ describe('Integration Capture', () => {
159163
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
160164
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
161165
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
166+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
162167
});
163168

164169
it('should add captured integrations to commerce event custom flags', async () => {
@@ -197,6 +202,7 @@ describe('Integration Capture', () => {
197202
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
198203
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
199204
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
205+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
200206
});
201207

202208
it('should add captured integrations to commerce event custom flags, prioritizing passed in flags', async () => {
@@ -235,6 +241,7 @@ describe('Integration Capture', () => {
235241
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
236242
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
237243
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
244+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
238245
});
239246

240247
it('should add captured integrations to commerce event custom flags', async () => {
@@ -273,6 +280,7 @@ describe('Integration Capture', () => {
273280
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
274281
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
275282
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
283+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
276284
});
277285

278286
it('should add captured integrations to commerce event custom flags, prioritizing passed in flags', async () => {
@@ -311,6 +319,7 @@ describe('Integration Capture', () => {
311319
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
312320
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
313321
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
322+
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
314323
});
315324

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

0 commit comments

Comments
 (0)