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

Extended ID permissions supported by bidder #6112

Merged
merged 20 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
},
{
name: "sharedId",
//bidders: ['rubicon', 'exBidder'], // to allow this ID for specific bidders
params: {
syncTime: 60 // in seconds, default is 24 hours
},
Expand Down
14 changes: 11 additions & 3 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import includes from 'core-js-pure/features/array/includes.js';
import { S2S_VENDORS } from './config.js';
import { ajax } from '../../src/ajax.js';
import find from 'core-js-pure/features/array/find.js';
import { getEidPermissions } from '../userId/index.js';

const getConfig = config.getConfig;

Expand Down Expand Up @@ -397,7 +398,7 @@ export function resetWurlMap() {
}

const OPEN_RTB_PROTOCOL = {
buildRequest(s2sBidRequest, bidRequests, adUnits) {
buildRequest(s2sBidRequest, bidRequests, adUnits, requestedBidders) {
let imps = [];
let aliases = {};
const firstBidRequest = bidRequests[0];
Expand Down Expand Up @@ -637,6 +638,14 @@ const OPEN_RTB_PROTOCOL = {
utils.deepSetValue(request, 'user.ext.eids', bidUserIdAsEids);
}

const eidPermissions = getEidPermissions();
if (utils.isArray(eidPermissions) && eidPermissions.length > 0) {
eidPermissions.forEach(i => {
i.bidders = i.bidders.filter(bidder => requestedBidders.includes(bidder) || bidder === '*');
});
utils.deepSetValue(request, 'ext.prebid.data.eidPermissions', eidPermissions);
YerkovichM marked this conversation as resolved.
Show resolved Hide resolved
}

if (bidRequests) {
if (firstBidRequest.gdprConsent) {
// note - gdprApplies & consentString may be undefined in certain use-cases for consentManagement module
Expand Down Expand Up @@ -888,8 +897,7 @@ export function PrebidServer() {

queueSync(syncBidders, gdprConsent, uspConsent);
}

const request = OPEN_RTB_PROTOCOL.buildRequest(s2sBidRequest, bidRequests, validAdUnits);
const request = OPEN_RTB_PROTOCOL.buildRequest(s2sBidRequest, bidRequests, validAdUnits, requestedBidders);
const requestJson = request && JSON.stringify(request);
if (request && requestJson) {
ajax(
Expand Down
21 changes: 21 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,24 @@ export function createEidsArray(bidRequestUserId) {
}
return eids;
}

/**
* @param {SubmoduleContainer[]} submodules
*/
export function buildEidPermissions(submodules) {
let eidPermissions = [];
submodules.filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length && i.config)
.forEach(i => {
Object.keys(i.idObj).forEach(key => {
if (utils.deepAccess(USER_IDS_CONFIG, key + '.source')) {
eidPermissions.push(
{
source: USER_IDS_CONFIG[key].source,
bidders: (i.config.bidders && Array.isArray(i.config.bidders) ? i.config.bidders : ['*'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this list of bidders is being sent to SSPs and likely will land in OpenRTB bid requests, should the name bidders in the eids object be changed to pbjs_bidders since it won't really apply to the openrtb world?

also, rather than ['*'] can we just omit bidders (or pbjs_bidders) altogether if none were set? This will avoid sending a field that isn't necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@smenzer changing bidders to pbjs_bidders seems fine to me. And yeah I agree omitting pbjs_bidders if none are set makes sense. Thanks.

}
)
}
});
});
return eidPermissions;
}
47 changes: 35 additions & 12 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ import { getGlobal } from '../../src/prebidGlobal.js';
import { gdprDataHandler } from '../../src/adapterManager.js';
import CONSTANTS from '../../src/constants.json';
import { module, hook } from '../../src/hook.js';
import { createEidsArray } from './eids.js';
import { createEidsArray, buildEidPermissions } from './eids.js';
import { getCoreStorageManager } from '../../src/storageManager.js';

const MODULE_NAME = 'User ID';
Expand Down Expand Up @@ -199,6 +199,10 @@ export function setStoredValue(submodule, value) {
}
}

export function getEidPermissions() {
return buildEidPermissions(initializedSubmodules);
}

/**
* @param {SubmoduleStorage} storage
* @param {String|undefined} key optional key of the value
Expand Down Expand Up @@ -364,6 +368,26 @@ function getCombinedSubmoduleIds(submodules) {
return combinedSubmoduleIds;
}

/**
* This function will create a combined object for bidder with allowed subModule Ids
* @param {SubmoduleContainer[]} submodules
* @param {string} bidder
*/
function getCombinedSubmoduleIdsForBidder(submodules, bidder) {
if (!Array.isArray(submodules) || !submodules.length || !bidder) {
return {};
}
return submodules
.filter(i => !(i.config.bidders && utils.isArray(i.config.bidders)) || i.config.bidders.includes(bidder))
.filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length)
.reduce((carry, i) => {
Object.keys(i.idObj).forEach(key => {
carry[key] = i.idObj[key];
});
return carry;
}, {});
}

/**
* @param {AdUnit[]} adUnits
* @param {SubmoduleContainer[]} submodules
Expand All @@ -372,19 +396,18 @@ function addIdDataToAdUnitBids(adUnits, submodules) {
if ([adUnits].some(i => !Array.isArray(i) || !i.length)) {
return;
}
const combinedSubmoduleIds = getCombinedSubmoduleIds(submodules);
const combinedSubmoduleIdsAsEids = createEidsArray(combinedSubmoduleIds);
if (Object.keys(combinedSubmoduleIds).length) {
adUnits.forEach(adUnit => {
if (adUnit.bids && utils.isArray(adUnit.bids)) {
adUnit.bids.forEach(bid => {
adUnits.forEach(adUnit => {
if (adUnit.bids && utils.isArray(adUnit.bids)) {
adUnit.bids.forEach(bid => {
const combinedSubmoduleIds = getCombinedSubmoduleIdsForBidder(submodules, bid.bidder);
if (Object.keys(combinedSubmoduleIds).length) {
// create a User ID object on the bid,
bid.userId = combinedSubmoduleIds;
bid.userIdAsEids = combinedSubmoduleIdsAsEids;
});
}
});
}
bid.userIdAsEids = createEidsArray(combinedSubmoduleIds);
}
});
}
});
}

/**
Expand Down
3 changes: 2 additions & 1 deletion plugins/eslint/validateImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function flagErrors(context, node, importPath) {
if (
path.dirname(absImportPath) === absModulePath || (
absImportPath.startsWith(absModulePath) &&
path.basename(absImportPath) === 'index.js'
path.basename(absImportPath) === 'index.js' &&
path.basename(absFileDir) !== 'prebidServerBidAdapter'
)
) {
context.report(node, `import "${importPath}" cannot require module entry point`);
Expand Down
46 changes: 21 additions & 25 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,17 +965,15 @@ describe('S2S Adapter', function () {
adapter.callBids(request, BID_REQUESTS, addBidResponse, done, ajax);

const requestBid = JSON.parse(server.requests[0].requestBody);

expect(requestBid.ext).to.deep.equal({
prebid: {
aliases: {
brealtime: 'appnexus'
},
auctiontimestamp: 1510852447530,
targeting: {
includebidderkeys: false,
includewinners: true
}
expect(requestBid.ext).to.haveOwnProperty('prebid');
expect(requestBid.ext.prebid).to.deep.include({
aliases: {
brealtime: 'appnexus'
},
auctiontimestamp: 1510852447530,
targeting: {
includebidderkeys: false,
includewinners: true
}
});
});
Expand All @@ -1000,17 +998,15 @@ describe('S2S Adapter', function () {
adapter.callBids(request, BID_REQUESTS, addBidResponse, done, ajax);

const requestBid = JSON.parse(server.requests[0].requestBody);

expect(requestBid.ext).to.deep.equal({
prebid: {
aliases: {
[alias]: 'appnexus'
},
auctiontimestamp: 1510852447530,
targeting: {
includebidderkeys: false,
includewinners: true
}
expect(requestBid.ext).to.haveOwnProperty('prebid');
expect(requestBid.ext.prebid).to.deep.include({
aliases: {
[alias]: 'appnexus'
},
auctiontimestamp: 1510852447530,
targeting: {
includebidderkeys: false,
includewinners: true
}
});
});
Expand Down Expand Up @@ -1319,7 +1315,7 @@ describe('S2S Adapter', function () {

expect(requestBid).to.haveOwnProperty('ext');
expect(requestBid.ext).to.haveOwnProperty('prebid');
expect(requestBid.ext.prebid).to.deep.equal({
expect(requestBid.ext.prebid).to.deep.include({
auctiontimestamp: 1510852447530,
foo: 'bar',
targeting: {
Expand Down Expand Up @@ -1351,7 +1347,7 @@ describe('S2S Adapter', function () {

expect(requestBid).to.haveOwnProperty('ext');
expect(requestBid.ext).to.haveOwnProperty('prebid');
expect(requestBid.ext.prebid).to.deep.equal({
expect(requestBid.ext.prebid).to.deep.include({
auctiontimestamp: 1510852447530,
targeting: {
includewinners: false,
Expand Down Expand Up @@ -1385,7 +1381,7 @@ describe('S2S Adapter', function () {

expect(requestBid).to.haveOwnProperty('ext');
expect(requestBid.ext).to.haveOwnProperty('prebid');
expect(requestBid.ext.prebid).to.deep.equal({
expect(requestBid.ext.prebid).to.deep.include({
auctiontimestamp: 1510852447530,
cache: {
vastxml: 'vastxml-set-though-extPrebid.cache.vastXml'
Expand Down
114 changes: 114 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
attachIdSystem,
auctionDelay,
coreStorage,
getEidPermissions,
init,
requestBidsHook,
setStoredConsentData,
Expand Down Expand Up @@ -1172,6 +1173,119 @@ describe('User ID', function () {
}, {adUnits});
});

it('eidPermissions fun with bidders', function (done) {
coreStorage.setCookie('sharedid', JSON.stringify({
'id': 'test222',
'ts': 1590525289611
}), (new Date(Date.now() + 5000).toUTCString()));

setSubmoduleRegistry([sharedIdSubmodule]);
init(config);
config.setConfig({
userSync: {
syncDelay: 0,
userIds: [
{
name: 'sharedId',
bidders: [
'rubicon',
'sampleBidder'
],
storage: {
type: 'cookie',
name: 'sharedid',
expires: 28
}
}
]
}
});

requestBidsHook(function () {
const eidPermissions = getEidPermissions();
expect(eidPermissions).to.deep.equal(
[
{source: 'sharedid.org', bidders: ['rubicon', 'sampleBidder']}
]
);
adUnits.forEach(unit => {
unit.bids.forEach(bid => {
if (bid.bidder === 'sampleBidder') {
expect(bid).to.have.deep.nested.property('userId.sharedid');
expect(bid.userId.sharedid.id).to.equal('test222');
expect(bid.userIdAsEids[0]).to.deep.equal({
source: 'sharedid.org',
uids: [
{
id: 'test222',
atype: 1,
ext: {
third: 'test222'
}
}
]
});
}
});
});
coreStorage.setCookie('sharedid', '', EXPIRED_COOKIE_DATE);
done();
}, {adUnits});
});

it('eidPermissions fun without bidders', function (done) {
coreStorage.setCookie('sharedid', JSON.stringify({
'id': 'test222',
'ts': 1590525289611
}), (new Date(Date.now() + 5000).toUTCString()));

setSubmoduleRegistry([sharedIdSubmodule]);
init(config);
config.setConfig({
userSync: {
syncDelay: 0,
userIds: [
{
name: 'sharedId',
storage: {
type: 'cookie',
name: 'sharedid',
expires: 28
}
}
]
}
});

requestBidsHook(function () {
const eidPermissions = getEidPermissions();
expect(eidPermissions).to.deep.equal(
[
{source: 'sharedid.org', bidders: ['*']}
]
);
adUnits.forEach(unit => {
unit.bids.forEach(bid => {
expect(bid).to.have.deep.nested.property('userId.sharedid');
expect(bid.userId.sharedid.id).to.equal('test222');
expect(bid.userIdAsEids[0]).to.deep.equal({
source: 'sharedid.org',
uids: [
{
id: 'test222',
atype: 1,
ext: {
third: 'test222'
}
}]
});
});
});
coreStorage.setCookie('sharedid', '', EXPIRED_COOKIE_DATE);
done();
}, {adUnits});
});

it('test hook from pubProvidedId config params', function (done) {
setSubmoduleRegistry([pubProvidedIdSubmodule]);
init(config);
Expand Down