diff --git a/src/integrationCapture.ts b/src/integrationCapture.ts index 419228ef..c7162ea1 100644 --- a/src/integrationCapture.ts +++ b/src/integrationCapture.ts @@ -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 = { diff --git a/test/jest/integration-capture.spec.ts b/test/jest/integration-capture.spec.ts index 875179bb..a62a6bfa 100644 --- a/test/jest/integration-capture.spec.ts +++ b/test/jest/integration-capture.spec.ts @@ -27,7 +27,9 @@ describe('Integration Capture', () => { 'gbraid', 'wbraid', 'ttclid', - 'ScCid' + 'ScCid', + 'epik', + '_epik' ]); }); @@ -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); @@ -665,6 +759,7 @@ describe('Integration Capture', () => { _ttp: '0823422223.23234', ttclid: '12345', gclid: '123233.23131', + epik: 'pinterest123', invalidId: '12345', }; @@ -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', () => {