Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intentiq id module: cookie enabled param conflict resolution #10145

Merged
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
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