Skip to content
Open
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
13 changes: 13 additions & 0 deletions src/integrationCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ const integrationMappingExternal: IntegrationIdMapping = {
mappedKey: 'SnapchatConversions.ClickId',
output: IntegrationOutputs.CUSTOM_FLAGS,
},

// Pinterest
// https://help.pinterest.com/en/business/article/pinterest-tag-parameters-and-cookies
// https://help.pinterest.com/en/business/article/add-event-codes
// https://developers.pinterest.com/docs/track-conversions/track-conversions-in-the-api/
epik: {
mappedKey: 'Pinterest.click_id',
output: IntegrationOutputs.CUSTOM_FLAGS,
},
_epik: {
mappedKey: 'Pinterest.click_id',
output: IntegrationOutputs.CUSTOM_FLAGS,
},
};

const integrationMappingRokt: IntegrationIdMapping = {
Expand Down
113 changes: 112 additions & 1 deletion test/jest/integration-capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('Integration Capture', () => {
'gbraid',
'wbraid',
'ttclid',
'ScCid'
'ScCid',
'epik',
'_epik'
]);
});

Expand Down Expand Up @@ -275,6 +277,98 @@ describe('Integration Capture', () => {
});
});

describe('Pinterest Click Ids', () => {
it('should capture Pinterest specific click ids from query params (_epik)', () => {
const url = new URL('https://www.example.com/?_epik=1234');

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

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

expect(integrationCapture.clickIds).toEqual({
_epik: '1234',
});
});

it('should capture Pinterest specific click ids from query params (epik)', () => {
const url = new URL('https://www.example.com/?epik=5678');

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

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

expect(integrationCapture.clickIds).toEqual({
epik: '5678',
});
});

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

window.document.cookie = '_epik=pinterest_cookie_value';
window.location.href = url.href;
window.location.search = url.search;

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

expect(integrationCapture.clickIds).toEqual({
_epik: 'pinterest_cookie_value',
});
});

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

window.document.cookie = 'epik=pinterest_cookie_value_epik';
window.location.href = url.href;
window.location.search = url.search;

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

expect(integrationCapture.clickIds).toEqual({
epik: 'pinterest_cookie_value_epik',
});
});

it('should capture Pinterest specific click ids from localStorage (_epik)', () => {
const url = new URL('https://www.example.com/');

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

localStorage.setItem('_epik', 'pinterest_localstorage_value');

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

expect(integrationCapture.clickIds).toEqual({
_epik: 'pinterest_localstorage_value',
});
});

it('should capture Pinterest specific click ids from localStorage (epik)', () => {
const url = new URL('https://www.example.com/');

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

localStorage.setItem('epik', 'pinterest_localstorage_value_epik');

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

expect(integrationCapture.clickIds).toEqual({
epik: 'pinterest_localstorage_value_epik',
});
});
});

describe('Facebook Click Ids', () => {
it('should format fbclid correctly', () => {
jest.spyOn(Date, 'now').mockImplementation(() => 42);
Expand Down Expand Up @@ -665,6 +759,7 @@ describe('Integration Capture', () => {
_ttp: '0823422223.23234',
ttclid: '12345',
gclid: '123233.23131',
epik: 'pinterest123',
invalidId: '12345',
};

Expand All @@ -675,8 +770,24 @@ describe('Integration Capture', () => {
'Facebook.BrowserId': '54321',
'TikTok.Callback': '12345',
'GoogleEnhancedConversions.Gclid': '123233.23131',
'Pinterest.click_id': 'pinterest123',
});
});

it('should map both epik and _epik to Pinterest.click_id', () => {
const integrationCapture = new IntegrationCapture('all');
integrationCapture.clickIds = {
epik: 'pinterest_epik',
_epik: 'pinterest_underscore_epik',
};

const customFlags = integrationCapture.getClickIdsAsCustomFlags();

// Both map to the same key, last one wins (based on object iteration order)
expect(customFlags).toHaveProperty('Pinterest.click_id');
// The value will be one of them depending on iteration order
expect(['pinterest_epik', 'pinterest_underscore_epik']).toContain(customFlags['Pinterest.click_id']);
});
});

describe('#getClickIdsAsPartnerIdentites', () => {
Expand Down