Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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://developers.snap.com/api/marketing-api/Conversions-API/UsingTheAPI#sending-click-id
_scid: {
mappedKey: 'SnapchatConversions.Cookie1',
output: IntegrationOutputs.CUSTOM_FLAGS,
},
};

const integrationMappingRokt: IntegrationIdMapping = {
Expand Down
57 changes: 56 additions & 1 deletion test/jest/integration-capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'gbraid',
'wbraid',
'ttclid',
'ScCid'
'ScCid',
'_scid'
]);
});

Expand Down Expand Up @@ -55,6 +56,7 @@
'wbraid',
'ttclid',
'ScCid',
'_scid',
];
for (const key of excludedKeys) {
expect(mappings).not.toHaveProperty(key);
Expand Down Expand Up @@ -273,6 +275,42 @@
ScCid: '1234',
});
});

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

window.document.cookie = '_scid=cookie1-from-cookie';

Check warning on line 282 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqdfXAF4HmqF-lsaE7u&open=AZqdfXAF4HmqF-lsaE7u&pullRequest=1118
window.document.cookie = '_cookie1=4567';

Check warning on line 283 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo444&open=AZqcoGV3Qvmg43Lmo444&pullRequest=1118
window.document.cookie = 'baz=qux';

Check warning on line 284 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo445&open=AZqcoGV3Qvmg43Lmo445&pullRequest=1118

window.location.href = url.href;

Check warning on line 286 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo44z&open=AZqcoGV3Qvmg43Lmo44z&pullRequest=1118
window.location.search = url.search;

Check warning on line 287 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo440&open=AZqcoGV3Qvmg43Lmo440&pullRequest=1118

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

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

it('should capture both ScCid from query params and _scid from cookies', () => {
const url = new URL('https://www.example.com/?ScCid=4567');

window.document.cookie = '_scid=cookie1-from-cookie';

Check warning on line 300 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqdfXAF4HmqF-lsaE7v&open=AZqdfXAF4HmqF-lsaE7v&pullRequest=1118
window.document.cookie = '_cookie1=334455';

Check warning on line 301 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqdfXAF4HmqF-lsaE7w&open=AZqdfXAF4HmqF-lsaE7w&pullRequest=1118

window.location.href = url.href;

Check warning on line 303 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo441&open=AZqcoGV3Qvmg43Lmo441&pullRequest=1118
window.location.search = url.search;

Check warning on line 304 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo442&open=AZqcoGV3Qvmg43Lmo442&pullRequest=1118

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

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

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

it('should capture _scid from cookies', () => {
window.document.cookie = '_cookie1=4567';

Check warning on line 653 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo446&open=AZqcoGV3Qvmg43Lmo446&pullRequest=1118
window.document.cookie = '_scid=cookie1-from-cookie';

Check warning on line 654 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqdfXAF4HmqF-lsaE7x&open=AZqdfXAF4HmqF-lsaE7x&pullRequest=1118
window.document.cookie = 'baz=qux';

Check warning on line 655 in test/jest/integration-capture.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqcoGV3Qvmg43Lmo448&open=AZqcoGV3Qvmg43Lmo448&pullRequest=1118

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

expect(clickIds).toEqual({
_scid: '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 +716,8 @@
_ttp: '0823422223.23234',
ttclid: '12345',
gclid: '123233.23131',
ScCid: '456789',
_scid: 'cookie1-value',
invalidId: '12345',
};

Expand All @@ -675,6 +728,8 @@
'Facebook.BrowserId': '54321',
'TikTok.Callback': '12345',
'GoogleEnhancedConversions.Gclid': '123233.23131',
'SnapchatConversions.ClickId': '456789',
'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 @@ -45,6 +45,7 @@
window.document.cookie = '_fbp=54321';
window.document.cookie = 'baz=qux';
window.document.cookie = '_ttp=45670808';
window.document.cookie = '_scid=cookie1-value';

Check warning on line 48 in test/src/tests-integration-capture.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZqdfW814HmqF-lsaE7t&open=AZqdfW814HmqF-lsaE7t&pullRequest=1118
mParticle.init(apiKey, window.mParticle.config);
await waitForCondition(hasIdentifyReturned);
const integrationCapture = window.mParticle.getInstance()._IntegrationCapture;
Expand Down Expand Up @@ -89,6 +90,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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