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

LiveIntent UserId module: update LiveConnect dependency #9672

Merged
merged 8 commits into from
Mar 21, 2023
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
24 changes: 20 additions & 4 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LiveConnect } from 'live-connect-js'; // eslint-disable-line prebid/val
import { gdprDataHandler, uspDataHandler } from '../src/adapterManager.js';
import { getStorageManager } from '../src/storageManager.js';

const EVENTS_TOPIC = 'pre_lips'
const MODULE_NAME = 'liveIntentId';
export const storage = getStorageManager({gvlid: null, moduleName: MODULE_NAME});
const defaultRequestedAttributes = {'nonId': true}
Expand Down Expand Up @@ -39,14 +40,22 @@ let liveConnect = null;
* This function is used in tests
*/
export function reset() {
if (window && window.liQ) {
window.liQ = [];
if (window && window.liQ_instances) {
window.liQ_instances.forEach(i => i.eventBus.off(EVENTS_TOPIC, setEventFiredFlag))
window.liQ_instances = [];
}
liveIntentIdSubmodule.setModuleMode(null)
eventFired = false;
liveConnect = null;
}

/**
* This function is also used in tests
*/
export function setEventFiredFlag() {
eventFired = true;
}

function parseLiveIntentCollectorConfig(collectConfig) {
const config = {};
collectConfig = collectConfig || {}
Expand Down Expand Up @@ -100,6 +109,7 @@ function initializeLiveConnect(configParams) {
liveConnectConfig.wrapperName = 'prebid';
liveConnectConfig.identityResolutionConfig = identityResolutionConfig;
liveConnectConfig.identifiersToResolve = configParams.identifiersToResolve || [];
liveConnectConfig.fireEventDelay = configParams.fireEventDelay;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only used for testing.

const usPrivacyString = uspDataHandler.getConsentData();
if (usPrivacyString) {
liveConnectConfig.usPrivacyString = usPrivacyString;
Expand All @@ -121,8 +131,14 @@ function initializeLiveConnect(configParams) {

function tryFireEvent() {
if (!eventFired && liveConnect) {
liveConnect.fire();
eventFired = true;
const eventDelay = liveConnect.config.fireEventDelay || 500
setTimeout(() => {
const instances = window.liQ_instances
instances.forEach(i => i.eventBus.once(EVENTS_TOPIC, setEventFiredFlag))
if (!eventFired && liveConnect) {
liveConnect.fire();
}
}, eventDelay)
Comment on lines +134 to +141
Copy link
Contributor Author

@3link 3link Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents duplicate events in cases where apart from LiveIntent's Prebid user id module another LiveConnect wrapper is installed on the same page. Mid term, the goal is to remove this guard and handle all events on the backend.

}
}

Expand Down
29 changes: 22 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"express": "^4.15.4",
"fun-hooks": "^0.9.9",
"just-clone": "^1.0.2",
"live-connect-js": "^4.0.0"
"live-connect-js": "^5.0.0"
},
"optionalDependencies": {
"fsevents": "^2.3.2"
Expand Down
73 changes: 47 additions & 26 deletions test/spec/modules/liveIntentIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { server } from 'test/mocks/xhr.js';
resetLiveIntentIdSubmodule();
liveIntentIdSubmodule.setModuleMode('standard')
const PUBLISHER_ID = '89899';
const defaultConfigParams = { params: {publisherId: PUBLISHER_ID} };
const defaultConfigParams = { params: {publisherId: PUBLISHER_ID, fireEventDelay: 1} };
const responseHeader = {'Content-Type': 'application/json'}

describe('LiveIntentId', function() {
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('LiveIntentId', function() {
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.match(/.*us_privacy=1YNY.*&gdpr=1&n3pc=1&gdpr_consent=consentDataString.*/);
const response = {
unifiedId: 'a_unified_id',
Expand All @@ -59,25 +59,31 @@ describe('LiveIntentId', function() {
expect(callBackSpy.calledOnceWith(response)).to.be.true;
});

it('should fire an event when getId', function() {
it('should fire an event when getId', function(done) {
uspConsentDataStub.returns('1YNY');
gdprConsentDataStub.returns({
gdprApplies: true,
consentString: 'consentDataString'
})
liveIntentIdSubmodule.getId(defaultConfigParams);
expect(server.requests[0].url).to.match(/https:\/\/rp.liadm.com\/j\?.*&us_privacy=1YNY.*&wpn=prebid.*&gdpr=1&n3pc=1&n3pct=1&nb=1&gdpr_consent=consentDataString.*/);
setTimeout(() => {
expect(server.requests[0].url).to.match(/https:\/\/rp.liadm.com\/j\?.*&us_privacy=1YNY.*&wpn=prebid.*&gdpr=1&n3pc=1&n3pct=1&nb=1&gdpr_consent=consentDataString.*/);
done();
}, 200);
});

it('should fire an event when getId and a hash is provided', function() {
it('should fire an event when getId and a hash is provided', function(done) {
liveIntentIdSubmodule.getId({ params: {
...defaultConfigParams,
emailHash: '58131bc547fb87af94cebdaf3102321f'
}});
expect(server.requests[0].url).to.match(/https:\/\/rp.liadm.com\/j\?.*e=58131bc547fb87af94cebdaf3102321f.+/)
setTimeout(() => {
expect(server.requests[0].url).to.match(/https:\/\/rp.liadm.com\/j\?.*e=58131bc547fb87af94cebdaf3102321f.+/)
done();
}, 200);
});

it('should initialize LiveConnect with the config params when decode and emit an event', function () {
it('should initialize LiveConnect with the config params when decode and emit an event', function (done) {
liveIntentIdSubmodule.decode({}, { params: {
...defaultConfigParams.params,
...{
Expand All @@ -88,51 +94,66 @@ describe('LiveIntentId', function() {
}
}
}});
expect(server.requests[0].url).to.match(/https:\/\/collector.liveintent.com\/j\?.*aid=a-0001.*&wpn=prebid.*/);
setTimeout(() => {
expect(server.requests[0].url).to.match(/https:\/\/collector.liveintent.com\/j\?.*aid=a-0001.*&wpn=prebid.*/);
done();
}, 200);
});

it('should initialize LiveConnect and emit an event with a privacy string when decode', function() {
it('should initialize LiveConnect and emit an event with a privacy string when decode', function(done) {
uspConsentDataStub.returns('1YNY');
gdprConsentDataStub.returns({
gdprApplies: false,
consentString: 'consentDataString'
})
liveIntentIdSubmodule.decode({}, defaultConfigParams);
expect(server.requests[0].url).to.match(/.*us_privacy=1YNY.*&gdpr=0&gdpr_consent=consentDataString.*/);
setTimeout(() => {
expect(server.requests[0].url).to.match(/.*us_privacy=1YNY.*&gdpr=0&gdpr_consent=consentDataString.*/);
done();
}, 200);
});

it('should fire an event when decode and a hash is provided', function() {
it('should fire an event when decode and a hash is provided', function(done) {
liveIntentIdSubmodule.decode({}, { params: {
...defaultConfigParams.params,
emailHash: '58131bc547fb87af94cebdaf3102321f'
}});
expect(server.requests[0].url).to.match(/https:\/\/rp.liadm.com\/j\?.*e=58131bc547fb87af94cebdaf3102321f.+/);
setTimeout(() => {
expect(server.requests[0].url).to.match(/https:\/\/rp.liadm.com\/j\?.*e=58131bc547fb87af94cebdaf3102321f.+/);
done();
}, 200);
});

it('should not return a decoded identifier when the unifiedId is not present in the value', function() {
const result = liveIntentIdSubmodule.decode({ additionalData: 'data' });
expect(result).to.be.eql({});
});

it('should fire an event when decode', function() {
it('should fire an event when decode', function(done) {
liveIntentIdSubmodule.decode({}, defaultConfigParams);
expect(server.requests[0].url).to.be.not.null
setTimeout(() => {
expect(server.requests[0].url).to.be.not.null
done();
}, 200);
});

it('should initialize LiveConnect and send data only once', function() {
it('should initialize LiveConnect and send data only once', function(done) {
liveIntentIdSubmodule.getId(defaultConfigParams);
liveIntentIdSubmodule.decode({}, defaultConfigParams);
liveIntentIdSubmodule.getId(defaultConfigParams);
liveIntentIdSubmodule.decode({}, defaultConfigParams);
expect(server.requests.length).to.be.eq(1);
setTimeout(() => {
expect(server.requests.length).to.be.eq(1);
done();
}, 200);
});

it('should call the Custom URL of the LiveIntent Identity Exchange endpoint', function() {
it('should call the custom URL of the LiveIntent Identity Exchange endpoint', function() {
getCookieStub.returns(null);
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId({ params: {...defaultConfigParams.params, ...{'url': 'https://dummy.liveintent.com/idex'}} }).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/prebid/89899?resolve=nonId');
request.respond(
204,
Expand All @@ -152,7 +173,7 @@ describe('LiveIntentId', function() {
}
} }).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/rubicon/89899?resolve=nonId');
request.respond(
200,
Expand All @@ -167,7 +188,7 @@ describe('LiveIntentId', function() {
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899?resolve=nonId');
request.respond(
200,
Expand All @@ -182,7 +203,7 @@ describe('LiveIntentId', function() {
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899?resolve=nonId');
request.respond(
503,
Expand All @@ -199,7 +220,7 @@ describe('LiveIntentId', function() {
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?duid=${oldCookie}&resolve=nonId`);
request.respond(
200,
Expand All @@ -222,7 +243,7 @@ describe('LiveIntentId', function() {
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(configParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?duid=${oldCookie}&_thirdPC=third-pc&resolve=nonId`);
request.respond(
200,
Expand All @@ -244,7 +265,7 @@ describe('LiveIntentId', function() {
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(configParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899?_thirdPC=%7B%22key%22%3A%22value%22%7D&resolve=nonId');
request.respond(
200,
Expand Down Expand Up @@ -277,7 +298,7 @@ describe('LiveIntentId', function() {
...{ requestedAttributesOverrides: { 'foo': true, 'bar': false } }
} }).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?resolve=nonId&resolve=foo`);
request.respond(
200,
Expand All @@ -304,7 +325,7 @@ describe('LiveIntentId', function() {
...{ requestedAttributesOverrides: { 'nonId': false, 'uid2': true } }
} }).callback;
submoduleCallback(callBackSpy);
let request = server.requests[1];
let request = server.requests[0];
expect(request.url).to.be.eq(`https://idx.liadm.com/idex/prebid/89899?resolve=uid2`);
request.respond(
200,
Expand Down
3 changes: 2 additions & 1 deletion test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {britepoolIdSubmodule} from 'modules/britepoolIdSystem.js';
import {id5IdSubmodule} from 'modules/id5IdSystem.js';
import {identityLinkSubmodule} from 'modules/identityLinkIdSystem.js';
import {dmdIdSubmodule} from 'modules/dmdIdSystem.js';
import {liveIntentIdSubmodule} from 'modules/liveIntentIdSystem.js';
import {liveIntentIdSubmodule, setEventFiredFlag as liveIntentIdSubmoduleDoNotFireEvent} from 'modules/liveIntentIdSystem.js';
import {merkleIdSubmodule} from 'modules/merkleIdSystem.js';
import {netIdSubmodule} from 'modules/netIdSystem.js';
import {intentIqIdSubmodule} from 'modules/intentIqIdSystem.js';
Expand Down Expand Up @@ -147,6 +147,7 @@ describe('User ID', function () {
hook.ready();
uninstallGdprEnforcement();
localStorage.removeItem(PBJS_USER_ID_OPTOUT_NAME);
liveIntentIdSubmoduleDoNotFireEvent();
});

beforeEach(function () {
Expand Down