Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/integrationCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ const integrationMappingExternal: IntegrationIdMapping = {
mappedKey: 'SnapchatConversions.ClickId',
output: IntegrationOutputs.CUSTOM_FLAGS,
},
// Snapchat
// https://businesshelp.snapchat.com/s/article/capi-gtm-examples?language=en_US
sc_cookie1: {
mappedKey: 'SnapchatConversions.Cookie1',
output: IntegrationOutputs.CUSTOM_FLAGS,
},
};

const integrationMappingRokt: IntegrationIdMapping = {
Expand Down
80 changes: 74 additions & 6 deletions test/jest/integration-capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('Integration Capture', () => {
'gbraid',
'wbraid',
'ttclid',
'ScCid'
'ScCid',
'sc_cookie1'
]);
});

Expand Down Expand Up @@ -55,6 +56,7 @@ describe('Integration Capture', () => {
'wbraid',
'ttclid',
'ScCid',
'sc_cookie1',

Choose a reason for hiding this comment

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

Apologies for the confusion here. They cookie key you should capture is _scid. sc_cookie1 is the parameter name that this value is sent to CAPI as. Some information about this can be found here.

];
for (const key of excludedKeys) {
expect(mappings).not.toHaveProperty(key);
Expand Down Expand Up @@ -106,7 +108,7 @@ describe('Integration Capture', () => {
it('should return all mapped keys from helpers when captureMode is all (lowercase)', () => {
jest.spyOn(Date, 'now').mockImplementation(() => 42);
// Query params
const url = new URL('https://www.example.com/?fbclid=abc&gclid=g1&rtid=rt1&rclid=rc1&ScCid=snap1');
const url = new URL('https://www.example.com/?fbclid=abc&gclid=g1&rtid=rt1&rclid=rc1&ScCid=snap1&sc_cookie1=cookie1');

Choose a reason for hiding this comment

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

The cookie ID (_scid) would only be found in the cookies. We wouldn't expect to see it as a URL parameter.

window.location.href = url.href;
window.location.search = url.search;

Expand All @@ -125,15 +127,15 @@ describe('Integration Capture', () => {
const clickIdLocalStorage = integrationCapture.captureLocalStorage();

// fbclid is formatted with timestamp/domain index
expect(clickIds).toMatchObject({ fbclid: 'fb.2.42.abc', gclid: 'g1', rtid: 'rt1', rclid: 'rc1', ScCid: 'snap1' });
expect(clickIds).toMatchObject({ fbclid: 'fb.2.42.abc', gclid: 'g1', rtid: 'rt1', rclid: 'rc1', ScCid: 'snap1', sc_cookie1: 'cookie1' });
expect(clickIdCookies).toMatchObject({ _fbp: '54321', _fbc: 'fb.1.1554763741205.abcdef', RoktTransactionId: 'xyz' });
expect(clickIdLocalStorage).toEqual({ RoktTransactionId: 'ls-rok' });
});

it('should NOT return mapped keys from helpers when captureMode is none (lowercase)', () => {
jest.spyOn(Date, 'now').mockImplementation(() => 42);
// Query params
const url = new URL('https://www.example.com/?fbclid=abc&gclid=g1&rtid=rt1&rclid=rc1&ScCid=snap1');
const url = new URL('https://www.example.com/?fbclid=abc&gclid=g1&rtid=rt1&rclid=rc1&ScCid=snap1&sc_cookie1=cookie1');
window.location.href = url.href;
window.location.search = url.search;

Expand Down Expand Up @@ -199,7 +201,8 @@ describe('Integration Capture', () => {
'wbraid=09876',
'rtid=84324',
'rclid=7183717',
'ScCid=1234'
'ScCid=1234',
'sc_cookie1=cookie1-value'
].join('&');

const url = new URL(`https://www.example.com/?${queryParams}`);
Expand All @@ -223,7 +226,8 @@ describe('Integration Capture', () => {
rtid: '84324',
rclid: '7183717',
wbraid: '09876',
ScCid:'1234'
ScCid:'1234',
sc_cookie1: 'cookie1-value'
});
});

Expand Down Expand Up @@ -273,6 +277,53 @@ describe('Integration Capture', () => {
ScCid: '1234',
});
});

it('should capture sc_cookie1', () => {
const url = new URL('https://www.example.com/?sc_cookie1=cookie1-value');

window.location.href = url.href;
window.location.search = url.search;

const integrationCapture = new IntegrationCapture('all');
integrationCapture.capture();

expect(integrationCapture.clickIds).toEqual({
sc_cookie1: 'cookie1-value',
});
});

it('should capture both ScCid and sc_cookie1', () => {
const url = new URL('https://www.example.com/?ScCid=1234&sc_cookie1=cookie1-value');

window.location.href = url.href;
window.location.search = url.search;

const integrationCapture = new IntegrationCapture('all');
integrationCapture.capture();

expect(integrationCapture.clickIds).toEqual({
ScCid: '1234',
sc_cookie1: 'cookie1-value',
});
});

it('should capture sc_cookie1 from cookies', () => {
const url = new URL('https://www.example.com/');

window.document.cookie = 'sc_cookie1=cookie1-from-cookie';
window.document.cookie = '_cookie1=1234';
window.document.cookie = 'baz=qux';

window.location.href = url.href;
window.location.search = url.search;

const integrationCapture = new IntegrationCapture('all');
integrationCapture.capture();

expect(integrationCapture.clickIds).toEqual({
sc_cookie1: 'cookie1-from-cookie',
});
});
});

describe('Facebook Click Ids', () => {
Expand Down Expand Up @@ -611,6 +662,19 @@ describe('Integration Capture', () => {
});
});

it('should capture sc_cookie1 from cookies', () => {
window.document.cookie = '_cookie1=1234';
window.document.cookie = 'sc_cookie1=cookie1-from-cookie';
window.document.cookie = 'baz=qux';

const integrationCapture = new IntegrationCapture('all');
const clickIds = integrationCapture.captureCookies();

expect(clickIds).toEqual({
sc_cookie1: 'cookie1-from-cookie',
});
});

it('should NOT capture cookies if they are not mapped', () => {
window.document.cookie = '_cookie1=1234';
window.document.cookie = '_cookie2=39895811.9165333198';
Expand Down Expand Up @@ -665,6 +729,8 @@ describe('Integration Capture', () => {
_ttp: '0823422223.23234',
ttclid: '12345',
gclid: '123233.23131',
ScCid: '1234',
sc_cookie1: 'cookie1-value',
invalidId: '12345',
};

Expand All @@ -675,6 +741,8 @@ describe('Integration Capture', () => {
'Facebook.BrowserId': '54321',
'TikTok.Callback': '12345',
'GoogleEnhancedConversions.Gclid': '123233.23131',
'SnapchatConversions.ClickId': '1234',
'SnapchatConversions.Cookie1': 'cookie1-value',
});
});
});
Expand Down
9 changes: 9 additions & 0 deletions test/src/tests-integration-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('Integration Capture', () => {
rclid: '7183717',
wbraid: '1234111',
ScCid: '1234',
sc_cookie1: 'cookie1-value',
});
integrationCapture.capture();
});
Expand Down Expand Up @@ -89,6 +90,7 @@ describe('Integration Capture', () => {
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Gbraid'], 'Google Enhanced Conversions Gbraid').to.equal('6574');
expect(testEvent.data.custom_flags['GoogleEnhancedConversions.Wbraid'], 'Google Enhanced Conversions Wbraid').to.equal('1234111');
expect(testEvent.data.custom_flags['SnapchatConversions.ClickId'], 'Snapchat Click ID').to.equal('1234');
expect(testEvent.data.custom_flags['SnapchatConversions.Cookie1'], 'Snapchat Cookie1').to.equal('cookie1-value');
});

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

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

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

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

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

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

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

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