Skip to content

Commit

Permalink
Intentiq id module: cookie enabled param conflict resolution (#10145)
Browse files Browse the repository at this point in the history
* added: enableCookieStorage parameter

* eslint fix

* added: tests for enableCookieStorage parameter

---------

Co-authored-by: Eyvaz Ahmadzada <eyvaz.ahmedzade.12@gmail.com>
  • Loading branch information
JulianRSL and eyvazahmadzada authored Jun 26, 2023
1 parent 7373d43 commit 40f7375
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
11 changes: 6 additions & 5 deletions modules/intentIqIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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');
}
}
Expand Down Expand Up @@ -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;

Expand All @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 36 additions & 2 deletions test/spec/modules/intentIqIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 40f7375

Please sign in to comment.