diff --git a/modules/intentIqIdSystem.js b/modules/intentIqIdSystem.js index 4a6977973f3..36454394841 100644 --- a/modules/intentIqIdSystem.js +++ b/modules/intentIqIdSystem.js @@ -59,7 +59,7 @@ export function readData(key) { * @param key * @param {string} value IntentIQ ID value to sintentIqIdSystem_spec.jstore */ -function storeData(key, value) { +function storeData(key, value, cookieStorageEnabled = false) { try { logInfo(MODULE_NAME + ': storing data: key=' + key + ' value=' + value); @@ -68,7 +68,7 @@ function storeData(key, value) { storage.setDataInLocalStorage(key, value); } const expiresStr = (new Date(Date.now() + (PCID_EXPIRY * (60 * 60 * 24 * 1000)))).toUTCString(); - if (storage.cookiesAreEnabled()) { + if (storage.cookiesAreEnabled() && cookieStorageEnabled) { storage.setCookie(key, value, expiresStr, 'LAX'); } } @@ -119,6 +119,7 @@ export const intentIqIdSubmodule = { logError('User ID - intentIqId submodule requires a valid partner to be defined'); return; } + const cookieStorageEnabled = typeof configParams.enableCookieStorage === 'boolean' ? configParams.enableCookieStorage : false if (!FIRST_PARTY_DATA_KEY.includes(configParams.partner)) { FIRST_PARTY_DATA_KEY += '_' + configParams.partner; } let rrttStrtTime = 0; @@ -127,7 +128,7 @@ export const intentIqIdSubmodule = { if (!firstPartyData || !firstPartyData.pcid || firstPartyData.pcidDate) { const firstPartyId = generateGUID(); firstPartyData = { 'pcid': firstPartyId, 'pcidDate': Date.now() }; - storeData(FIRST_PARTY_KEY, JSON.stringify(firstPartyData)); + storeData(FIRST_PARTY_KEY, JSON.stringify(firstPartyData), cookieStorageEnabled); } let partnerData = tryParse(readData(FIRST_PARTY_DATA_KEY)); @@ -172,8 +173,8 @@ export const intentIqIdSubmodule = { } if (shouldUpdateLs === true) { partnerData.date = Date.now(); - storeData(FIRST_PARTY_KEY, JSON.stringify(firstPartyData)); - storeData(FIRST_PARTY_DATA_KEY, JSON.stringify(partnerData)); + storeData(FIRST_PARTY_KEY, JSON.stringify(firstPartyData), cookieStorageEnabled); + storeData(FIRST_PARTY_DATA_KEY, JSON.stringify(partnerData), cookieStorageEnabled); } callback(respJson.data); } else { diff --git a/test/spec/modules/intentIqIdSystem_spec.js b/test/spec/modules/intentIqIdSystem_spec.js index f9bfa577e3a..d5ffbf92d68 100644 --- a/test/spec/modules/intentIqIdSystem_spec.js +++ b/test/spec/modules/intentIqIdSystem_spec.js @@ -1,15 +1,17 @@ import { expect } from 'chai'; -import { intentIqIdSubmodule, readData, FIRST_PARTY_KEY } from 'modules/intentIqIdSystem.js'; +import { intentIqIdSubmodule, storage } from 'modules/intentIqIdSystem.js'; import * as utils from 'src/utils.js'; import { server } from 'test/mocks/xhr.js'; const partner = 10; const pai = '11'; const pcid = '12'; +const enableCookieStorage = true; const defaultConfigParams = { params: { partner: partner } }; const paiConfigParams = { params: { partner: partner, pai: pai } }; const pcidConfigParams = { params: { partner: partner, pcid: pcid } }; -const allConfigParams = { params: { partner: partner, pai: pai, pcid: pcid } }; +const enableCookieConfigParams = { params: { partner: partner, enableCookieStorage: enableCookieStorage } }; +const allConfigParams = { params: { partner: partner, pai: pai, pcid: pcid, enableCookieStorage: enableCookieStorage } }; const responseHeader = { 'Content-Type': 'application/json' } describe('IntentIQ tests', function () { @@ -62,6 +64,38 @@ describe('IntentIQ tests', function () { expect(submodule).to.be.undefined; }); + it('should not save data in cookie if enableCookieStorage configParam not set', function () { + let callBackSpy = sinon.spy(); + let submoduleCallback = intentIqIdSubmodule.getId(defaultConfigParams).callback; + submoduleCallback(callBackSpy); + let request = server.requests[0]; + expect(request.url).to.contain('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1&iiqidtype=2&iiqpcid='); + request.respond( + 200, + responseHeader, + JSON.stringify({ pid: 'test_pid', data: 'test_personid', ls: true }) + ); + expect(callBackSpy.calledOnce).to.be.true; + expect(storage.getCookie('_iiq_fdata_' + partner)).to.equal(null); + }); + + it('should save data in cookie if enableCookieStorage configParam set to true', function () { + let callBackSpy = sinon.spy(); + let submoduleCallback = intentIqIdSubmodule.getId(allConfigParams).callback; + submoduleCallback(callBackSpy); + let request = server.requests[0]; + expect(request.url).to.contain('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1&pcid=12&pai=11&iiqidtype=2&iiqpcid='); + request.respond( + 200, + responseHeader, + JSON.stringify({ pid: 'test_pid', data: 'test_personid', ls: true }) + ); + expect(callBackSpy.calledOnce).to.be.true; + const cookieValue = storage.getCookie('_iiq_fdata_' + partner) + expect(cookieValue).to.not.equal(null) + expect(JSON.parse(cookieValue).data).to.be.equal('test_personid'); + }); + it('should call the IntentIQ endpoint with only partner', function () { let callBackSpy = sinon.spy(); let submoduleCallback = intentIqIdSubmodule.getId(defaultConfigParams).callback;