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

Add Parrable ID submodule #4266

Merged
merged 22 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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: 11 additions & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@
refreshInSeconds: 8*3600 // Refresh frequency of cookies, defaulting to 'expires'
},

}, {
name: "parrableId",
params: {
// change to Parrable Partner Client ID(s) you received from the Parrable Partners you are using
partner: '30182847-e426-4ff9-b2b5-9ca1324ea09b'
},
storage: {
type: "cookie",
name: "_parrable_eid", // create a cookie with this name
expires: 365 // cookie can last for a year
}
}, {
name: "pubCommonId",
storage: {
Expand Down
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"digiTrustIdSystem",
"id5IdSystem",
"criteortusIdSystem",
"parrableIdSystem",
"liveIntentIdSystem"
],
"adpod": [
Expand Down
92 changes: 92 additions & 0 deletions modules/parrableIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* This module adds Parrable to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/parrableIdSystem
* @requires module:modules/userId
*/

import * as utils from '../src/utils'
import {ajax} from '../src/ajax';
import {submodule} from '../src/hook';

const PARRABLE_URL = 'https://h.parrable.com/prebid';

function isValidConfig(configParams) {
if (!configParams) {
utils.logError('User ID - parrableId submodule requires configParams');
return false;
}
if (!configParams.partner) {
utils.logError('User ID - parrableId submodule requires partner list');
return false;
}
return true;
}

function fetchId(configParams, consentData, currentStoredId) {
if (!isValidConfig(configParams)) return;

const data = {
eid: currentStoredId || null,
trackers: configParams.partner.split(',')
};

const searchParams = {
data: btoa(JSON.stringify(data)),
_rand: Math.random()
};

const options = {
method: 'GET',
withCredentials: true
};

const callback = function (cb) {
const onSuccess = (response) => {
let eid;
if (response) {
try {
let responseObj = JSON.parse(response);
eid = responseObj ? responseObj.eid : undefined;
} catch (error) {
utils.logError(error);
}
}
cb(eid);
};
ajax(PARRABLE_URL, onSuccess, searchParams, options);
};

return { callback };
};

/** @type {Submodule} */
export const parrableIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'parrableId',
/**
* decode the stored id value for passing to bid requests
* @function
* @param {Object|string} value
* @return {(Object|undefined}
*/
decode(value) {
return (value && typeof value === 'string') ? { 'parrableid': value } : undefined;
},

/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @param {ConsentData} [consentData]
* @returns {function(callback:function)}
*/
getId(configParams, consentData, currentStoredId) {
return fetchId(configParams, consentData, currentStoredId);
}
};

submodule('userId', parrableIdSubmodule);
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 || bidUserId.lipb)) {
if (bidUserId && typeof bidUserId === 'object' && (bidUserId.tdid || bidUserId.pubcid || bidUserId.parrableid || bidUserId.lipb)) {
utils.deepSetValue(request, 'user.ext.eids', []);

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

if (bidUserId.parrableid) {
request.user.ext.eids.push({
source: 'parrable.com',
uids: [{
id: bidUserId.parrableid
}]
});
}

if (bidUserId.lipb && bidUserId.lipb.lipbid) {
request.user.ext.eids.push({
source: 'liveintent.com',
Expand Down
1 change: 1 addition & 0 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function initSubmodules(submodules, consentData) {
utils.logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`);
return [];
}

return submodules.reduce((carry, submodule) => {
// There are two submodule configuration types to handle: storage or value
// 1. storage: retrieve user id data from cookie/html storage or with the submodule's getId method
Expand Down
11 changes: 11 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ pbjs.setConfig({
name: "id5id",
expires: 5, // Expiration of cookies in days
refreshInSeconds: 8*3600 // User Id cache lifetime in seconds, defaulting to 'expires'
},
}, {
name: 'parrableId',
params: {
// Replace the list contents with the Parrable Partner Client IDs for Parrable-aware bid adapters in use
partners: [ "30182847-e426-4ff9-b2b5-9ca1324ea09b" ]
},
storage: {
type: 'cookie',
name: '_parrable_eid',
expires: 365
}
}, {
name: 'identityLink',
Expand Down
77 changes: 77 additions & 0 deletions test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expect } from 'chai';
import {config} from 'src/config';
import * as utils from 'src/utils';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';
import { parrableIdSubmodule } from 'modules/parrableIdSystem';

const EXPIRED_COOKIE_DATE = 'Thu, 01 Jan 1970 00:00:01 GMT';
const P_COOKIE_NAME = '_parrable_eid';
const P_COOKIE_VALUE = '01.1563917337.test-eid';
const P_CONFIG_MOCK = {
name: 'parrableId',
params: {
partner: 'parrable_test_partner_123,parrable_test_partner_456'
},
storage: {
name: '_parrable_eid',
type: 'cookie',
expires: 364
}
};

describe('Parrable ID System', function() {
function getConfigMock() {
return {
userSync: {
syncDelay: 0,
userIds: [P_CONFIG_MOCK]
}
}
}
function getAdUnitMock(code = 'adUnit-code') {
return {
code,
mediaTypes: {banner: {}, native: {}},
sizes: [
[300, 200],
[300, 600]
],
bids: [{
bidder: 'sampleBidder',
params: { placementId: 'banner-only-bidder' }
}]
};
}

describe('Parrable ID in Bid Request', function() {
let adUnits;

beforeEach(function() {
adUnits = [getAdUnitMock()];
});

it('should append parrableid to bid request', function(done) {
// simulate existing browser local storage values
utils.setCookie(
P_COOKIE_NAME,
P_COOKIE_VALUE,
(new Date(Date.now() + 5000).toUTCString())
);

setSubmoduleRegistry([parrableIdSubmodule]);
init(config);
config.setConfig(getConfigMock());

requestBidsHook(function() {
adUnits.forEach(unit => {
unit.bids.forEach(bid => {
expect(bid).to.have.deep.nested.property('userId.parrableid');
expect(bid.userId.parrableid).to.equal(P_COOKIE_VALUE);
});
});
utils.setCookie(P_COOKIE_NAME, '', EXPIRED_COOKIE_DATE);
done();
}, { adUnits });
});
});
});
3 changes: 3 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ describe('S2S Adapter', function () {
userIdBidRequest[0].bids[0].userId = {
tdid: 'abc123',
pubcid: '1234',
parrableid: '01.1563917337.test-eid',
lipb: {
lipbid: 'li-xyz'
}
Expand All @@ -1057,6 +1058,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 === 'parrable.com')).is.not.empty;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'parrable.com')[0].uids[0].id).is.equal('01.1563917337.test-eid');
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'liveintent.com')).is.not.empty;
expect(requestBid.user.ext.eids.filter(eid => eid.source === 'liveintent.com')[0].uids[0].id).is.equal('li-xyz');
});
Expand Down