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 Identity Module. #4178

Merged
merged 19 commits into from
Oct 14, 2019
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
3 changes: 2 additions & 1 deletion modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"userId": [
"digiTrustIdSystem",
"id5IdSystem",
"criteortusIdSystem"
"criteortusIdSystem",
"liveIntentIdSystem"
],
"adpod": [
"freeWheelAdserverVideo",
Expand Down
97 changes: 97 additions & 0 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* This module adds LiveIntentId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/liveIntentIdSystem
* @requires module:modules/userId
*/
import * as utils from '../src/utils'
import {ajax} from '../src/ajax';
import {submodule} from '../src/hook';

const MODULE_NAME = 'liveIntentId';
const LIVE_CONNECT_DUID_KEY = '_li_duid';
const DOMAIN_USER_ID_QUERY_PARAM_KEY = 'duid';
const DEFAULT_LIVEINTENT_IDENTITY_URL = '//idx.liadm.com';
const DEFAULT_PREBID_SOURCE = 'prebid';

/** @type {Submodule} */
export const liveIntentIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,

/**
* decode the stored id value for passing to bid requests. Note that lipb object is a wrapper for everything, and
* internally it could contain more data other than `lipbid`(e.g. `segments`) depending on the `partner` and
* `publisherId` params.
* @function
* @param {{unifiedId:string}} value
* @returns {{lipb:Object}}
*/
decode(value) {
function composeIdObject(value) {
const base = {'lipbid': value['unifiedId']};
delete value.unifiedId;
return {'lipb': {...base, ...value}};
}
return (value && typeof value['unifiedId'] === 'string') ? composeIdObject(value) : undefined;
},

/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @returns {function(callback:function)}
*/
getId(configParams) {
const publisherId = configParams && configParams.publisherId;
if (!publisherId && typeof publisherId !== 'string') {
utils.logError(`${MODULE_NAME} - publisherId must be defined, not a '${publisherId}'`);
return;
}
let baseUrl = DEFAULT_LIVEINTENT_IDENTITY_URL;
let source = DEFAULT_PREBID_SOURCE;
if (configParams.url) {
baseUrl = configParams.url
}
if (configParams.partner) {
source = configParams.partner
}

const additionalIdentifierNames = configParams.identifiersToResolve || [];

const additionalIdentifiers = additionalIdentifierNames.concat([LIVE_CONNECT_DUID_KEY]).reduce((obj, identifier) => {
const value = utils.getCookie(identifier) || utils.getDataFromLocalStorage(identifier);
const key = identifier.replace(LIVE_CONNECT_DUID_KEY, DOMAIN_USER_ID_QUERY_PARAM_KEY);
if (value) {
if (typeof value === 'object') {
obj[key] = JSON.stringify(value);
} else {
obj[key] = value;
}
}
return obj
}, {});

const queryString = utils.parseQueryStringParameters(additionalIdentifiers)
const url = `${baseUrl}/idex/${source}/${publisherId}?${queryString}`;

return function (callback) {
ajax(url, response => {
let responseObj = {};
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
}, undefined, { method: 'GET', withCredentials: true });
}
}
};

submodule('userId', liveIntentIdSubmodule);
11 changes: 10 additions & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ const OPEN_RTB_PROTOCOL = {
}

const bidUserId = utils.deepAccess(bidRequests, '0.bids.0.userId');
if (bidUserId && typeof bidUserId === 'object' && (bidUserId.tdid || bidUserId.pubcid)) {
if (bidUserId && typeof bidUserId === 'object' && (bidUserId.tdid || bidUserId.pubcid || bidUserId.lipb)) {
utils.deepSetValue(request, 'user.ext.eids', []);

if (bidUserId.tdid) {
Expand All @@ -721,6 +721,15 @@ const OPEN_RTB_PROTOCOL = {
}]
});
}

if (bidUserId.lipb && bidUserId.lipb.lipbid) {
request.user.ext.eids.push({
source: 'liveIntent',
uids: [{
id: bidUserId.lipb.lipbid
}]
});
}
}

if (bidRequests && bidRequests[0].gdprConsent) {
Expand Down
2 changes: 2 additions & 0 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
* @property {(boolean|undefined)} create - create id if missing. default is true.
* @property {(boolean|undefined)} extend - extend expiration time on each access. default is false.
* @property {(string|undefined)} pid - placement id url param value
* @property {(string|undefined)} publisherId - the unique identifier of the publisher in question
* @property {(array|undefined)} identifiersToResolve - the identifiers from either ls|cookie to be attached to the getId query
*/

/**
Expand Down
20 changes: 20 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ pbjs.setConfig({
name: 'idl_env',
expires: 30
}
}, {
name: 'liveIntentId',
params: {
publisherId: '7798696' // Set an identifier of a publisher know to your systems
},
storage: {
type: 'cookie',
name: '_li_pbid',
expires: 60
}
}],
syncDelay: 5000,
auctionDelay: 1000
Expand Down Expand Up @@ -82,6 +92,16 @@ pbjs.setConfig({
name: 'idl_env',
expires: 30
}
}, {
name: 'liveIntentId',
params: {
publisherId: '7798696' // Set an identifier of a publisher know to your systems
},
storage: {
type: 'html5',
name: '_li_pbid',
expires: 60
}
}],
syncDelay: 5000
}
Expand Down
145 changes: 145 additions & 0 deletions test/spec/modules/liveIntentIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { liveIntentIdSubmodule } from 'modules/liveIntentIdSystem';
import * as utils from 'src/utils';

describe('LiveIntentId', function() {
let xhr;
let requests;
let getCookieStub;
let getDataFromLocalStorageStub;
let logErrorStub;

const defaultConfigParams = {'publisherId': '89899'};
const responseHeader = { 'Content-Type': 'application/json' }

beforeEach(function () {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = request => requests.push(request);
getCookieStub = sinon.stub(utils, 'getCookie');
getDataFromLocalStorageStub = sinon.stub(utils, 'getDataFromLocalStorage');
logErrorStub = sinon.stub(utils, 'logError');
});

afterEach(function () {
xhr.restore();
getCookieStub.restore();
getDataFromLocalStorageStub.restore();
logErrorStub.restore();
});

it('should log an error if no configParams were passed', function() {
liveIntentIdSubmodule.getId();
expect(logErrorStub.calledOnce).to.be.true;
});

it('should log an error if publisherId configParam was not passed', function() {
liveIntentIdSubmodule.getId({});
expect(logErrorStub.calledOnce).to.be.true;
});

it('should call the Custom URL of the LiveIntent Identity Exchange endpoint', function() {
getCookieStub.returns(null);
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId({...defaultConfigParams, ...{'url': 'https://dummy.liveintent.com'}});
submoduleCallback(callBackSpy);
let request = requests[0];
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/prebid/89899?');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the default url of the LiveIntent Identity Exchange endpoint, with a partner', function() {
getCookieStub.returns(null);
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId({...defaultConfigParams, ...{'url': 'https://dummy.liveintent.com', 'partner': 'rubicon'}});
submoduleCallback(callBackSpy);
let request = requests[0];
expect(request.url).to.be.eq('https://dummy.liveintent.com/idex/rubicon/89899?');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the LiveIntent Identity Exchange endpoint, with no additional query params', function() {
getCookieStub.returns(null);
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams);
submoduleCallback(callBackSpy);
let request = requests[0];
expect(request.url).to.be.eq('//idx.liadm.com/idex/prebid/89899?');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should include the LiveConnect identifier when calling the LiveIntent Identity Exchange endpoint', function() {
getCookieStub.withArgs('_li_duid').returns('li-fpc');
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams);
submoduleCallback(callBackSpy);
let request = requests[0];
expect(request.url).to.be.eq('//idx.liadm.com/idex/prebid/89899?duid=li-fpc&');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should include the LiveConnect identifier and additional Identifiers to resolve', function() {
getCookieStub.withArgs('_li_duid').returns('li-fpc');
getDataFromLocalStorageStub.withArgs('_thirdPC').returns('third-pc');
let configParams = {
...defaultConfigParams,
...{
'identifiersToResolve': ['_thirdPC']
}
};

let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(configParams);
submoduleCallback(callBackSpy);
let request = requests[0];
expect(request.url).to.be.eq('//idx.liadm.com/idex/prebid/89899?_thirdPC=third-pc&duid=li-fpc&');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should include an additional identifier value to resolve even if it is an object', function() {
getCookieStub.returns(null);
getDataFromLocalStorageStub.withArgs('_thirdPC').returns({'key': 'value'});
let configParams = {
...defaultConfigParams,
...{
'identifiersToResolve': ['_thirdPC']
}
};

let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(configParams);
submoduleCallback(callBackSpy);
let request = requests[0];
expect(request.url).to.be.eq('//idx.liadm.com/idex/prebid/89899?_thirdPC=%7B%22key%22%3A%22value%22%7D&');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});
});
7 changes: 6 additions & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,10 @@ describe('S2S Adapter', function () {
let userIdBidRequest = utils.deepClone(BID_REQUESTS);
userIdBidRequest[0].bids[0].userId = {
tdid: 'abc123',
pubcid: '1234'
pubcid: '1234',
lipb: {
lipbid: 'li-xyz'
}
};

adapter.callBids(REQUEST, userIdBidRequest, addBidResponse, done, ajax);
Expand All @@ -1054,6 +1057,8 @@ describe('S2S Adapter', function () {
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'adserver.org')[0].uids[0].id).is.equal('abc123');
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')).is.not.empty;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')[0].uids[0].id).is.equal('1234');
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'liveIntent')).is.not.empty;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'liveIntent')[0].uids[0].id).is.equal('li-xyz');
});

it('when config \'currency.adServerCurrency\' value is an array: ORTB has property \'cur\' value set to a single item array', function () {
Expand Down
Loading