Skip to content

Commit

Permalink
New PubProvided Id UserId Submodule (#5767)
Browse files Browse the repository at this point in the history
* PubProvided Module

* -

* formatting

* formatting

* Added rubiconBidAdapter support
Added unit tests

* formatting

* formatting

* formatting

* formatting

* commit to rerun build

* type changes

* type changes

* type changes

* Revert "type changes"

This reverts commit af408b0

* Revert "type changes"

This reverts commit af408b0

* formatting

* formatting

* formatting

* formatting

* formatting

* Revert "type changes"

This reverts commit 114005a

* formatting

* formatting

* formatting

* formatting

* commit to rerun build

* commit to rerun build

* commit to rerun build

* rubiconBidAdapter changes

* rubiconBidAdapter changes

* rubiconBidAdapter changes

* trigger build

* fix

* fix

* fix

* rebuild

Co-authored-by: myerkovich <[email protected]>
  • Loading branch information
YerkovichM and MarkoYerkovichRP authored Sep 29, 2020
1 parent eb9cf3f commit 739bad8
Show file tree
Hide file tree
Showing 7 changed files with 513 additions and 201 deletions.
24 changes: 24 additions & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@
// },
userSync: {
userIds: [{
name: "pubProvidedId",
params: {
eids: [{
source: "domain.com",
uids:[{
id: "value read from cookie or local storage",
atype: 1,
ext: {
stype: "ppuid" // allowable options are sha256email, DMP, ppuid for now
}
}]
},{
source: "3rdpartyprovided.com",
uids:[{
id: "value read from cookie or local storage",
atype: 3,
ext: {
stype: "sha256email"
}
}]
}],
eidsFunction: getHashedEmail // any user defined function that exists in the page
}
},{
name: "unifiedId",
params: {
partner: "prebid",
Expand Down
53 changes: 53 additions & 0 deletions modules/pubProvidedSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This module adds Publisher Provided ids support to the User ID module
* The {@link module:modules/userId} module is required.
* @module modules/pubProvidedSystem
* @requires module:modules/userId
*/

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

const MODULE_NAME = 'pubProvidedId';

/** @type {Submodule} */
export const pubProvidedIdSubmodule = {

/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,

/**
* decode the stored id value for passing to bid request
* @function
* @param {string} value
* @returns {{pubProvidedId: array}} or undefined if value doesn't exists
*/
decode(value) {
const res = value ? {pubProvidedId: value} : undefined;
utils.logInfo('PubProvidedId: Decoded value ' + JSON.stringify(res));
return res;
},

/**
* performs action to obtain id and return a value.
* @function
* @param {SubmoduleParams} [configParams]
* @returns {{id: array}}
*/
getId(configParams) {
let res = [];
if (utils.isArray(configParams.eids)) {
res = res.concat(configParams.eids);
}
if (typeof configParams.eidsFunction === 'function') {
res = res.concat(configParams.eidsFunction());
}
return {id: res};
}
};

// Register submodule for userId
submodule('userId', pubProvidedIdSubmodule);
11 changes: 11 additions & 0 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,17 @@ export const spec = {
const configUserId = config.getConfig('user.id');
if (configUserId) {
data['ppuid'] = configUserId;
} else {
// if config.getConfig('user.id') doesn't return anything, then look for the first eid.uids[*].ext.stype === 'ppuid'
for (let i = 0; bidRequest.userIdAsEids && i < bidRequest.userIdAsEids.length; i++) {
if (bidRequest.userIdAsEids[i].uids) {
const pubProvidedId = find(bidRequest.userIdAsEids[i].uids, uid => uid.ext && uid.ext.stype === 'ppuid');
if (pubProvidedId && pubProvidedId.id) {
data['ppuid'] = pubProvidedId.id;
break;
}
}
}
}

if (bidderRequest.gdprConsent) {
Expand Down
10 changes: 7 additions & 3 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ export function createEidsArray(bidRequestUserId) {
let eids = [];
for (const subModuleKey in bidRequestUserId) {
if (bidRequestUserId.hasOwnProperty(subModuleKey)) {
const eid = createEidObject(bidRequestUserId[subModuleKey], subModuleKey);
if (eid) {
eids.push(eid);
if (subModuleKey === 'pubProvidedId') {
eids = eids.concat(bidRequestUserId['pubProvidedId']);
} else {
const eid = createEidObject(bidRequestUserId[subModuleKey], subModuleKey);
if (eid) {
eids.push(eid);
}
}
}
}
Expand Down
36 changes: 35 additions & 1 deletion test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,42 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});
it('pubProvidedId', function() {
const userId = {
pubProvidedId: [{
source: 'example.com',
uids: [{
id: 'value read from cookie or local storage',
ext: {
stype: 'ppuid'
}
}]
}, {
source: 'id-partner.com',
uids: [{
id: 'value read from cookie or local storage'
}]
}]
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(2);
expect(newEids[0]).to.deep.equal({
source: 'example.com',
uids: [{
id: 'value read from cookie or local storage',
ext: {
stype: 'ppuid'
}
}]
});
expect(newEids[1]).to.deep.equal({
source: 'id-partner.com',
uids: [{
id: 'value read from cookie or local storage'
}]
});
});
});

describe('Negative case', function() {
it('eids array generation for UN-known sub-module', function() {
// UnknownCommonId
Expand Down
Loading

0 comments on commit 739bad8

Please sign in to comment.