From 0bd6ab93281e3d227201e264f0f13b5da09f4529 Mon Sep 17 00:00:00 2001 From: Eyvaz Ahmadzada Date: Tue, 23 May 2023 10:32:11 +0100 Subject: [PATCH 1/3] added: enableCookieStorage parameter --- modules/intentIqIdSystem.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/intentIqIdSystem.js b/modules/intentIqIdSystem.js index b16624ac368..a95c1f61646 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,8 @@ 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 +129,7 @@ export const intentIqIdSubmodule = { if (!firstPartyData || !firstPartyData.pcid) { const firstPartyId = generateGUID(); firstPartyData = { 'pcid': firstPartyId }; - storeData(FIRST_PARTY_KEY, JSON.stringify(firstPartyData)); + storeData(FIRST_PARTY_KEY, JSON.stringify(firstPartyData), cookieStorageEnabled); } let partnerData = tryParse(readData(FIRST_PARTY_DATA_KEY)); @@ -171,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 { From 303fb438ed26be4a10fb6f19aa6383be53bab0b3 Mon Sep 17 00:00:00 2001 From: Eyvaz Ahmadzada Date: Tue, 23 May 2023 11:08:36 +0100 Subject: [PATCH 2/3] eslint fix --- modules/intentIqIdSystem.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/intentIqIdSystem.js b/modules/intentIqIdSystem.js index a95c1f61646..decf716b9ce 100644 --- a/modules/intentIqIdSystem.js +++ b/modules/intentIqIdSystem.js @@ -120,7 +120,6 @@ export const intentIqIdSubmodule = { 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; From a3fcd16a9fd9791bc7ddd481ed7d358ccd6973ec Mon Sep 17 00:00:00 2001 From: Eyvaz Ahmadzada Date: Wed, 24 May 2023 11:12:35 +0100 Subject: [PATCH 3/3] added: tests for enableCookieStorage parameter --- test/spec/modules/intentIqIdSystem_spec.js | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) 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;