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

NextRoll ID System: add new ID submodule #6396

Merged
merged 9 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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 modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"zeotapIdPlusIdSystem",
"haloIdSystem",
"quantcastIdSystem",
"nextrollIdSystem",
"idxIdSystem",
"fabrickIdSystem",
"verizonMediaIdSystem",
Expand Down
50 changes: 50 additions & 0 deletions modules/nextrollIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* This module adds Nextroll ID to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/nextrollIdSystem
* @requires module:modules/userId
*/

import { deepAccess } from '../src/utils.js';
import { submodule } from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';

const NEXTROLL_ID_LS_KEY = 'dca0.com';
const KEY_PREFIX = 'AdID:'

export const storage = getStorageManager();

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

/**
* decode the stored id value for passing to bid requests
* @function
* @return {{nextrollId: string} | undefined}
*/
decode(value) {
return value;
},

/**
* performs action to obtain id and return a value.
* @function
* @param {SubmoduleConfig} [config]
* @returns {{id: {nextrollId: string} | undefined}}
*/
getId(config) {
const key = KEY_PREFIX + deepAccess(config, 'params.partnerId', 'undefined');
const dataString = storage.getDataFromLocalStorage(NEXTROLL_ID_LS_KEY) || '{}';
const data = JSON.parse(dataString);
const idValue = deepAccess(data, `${key}.value`);

return { id: idValue ? {nextrollId: idValue} : undefined };
}
};

submodule('userId', nextrollIdSubmodule);
6 changes: 6 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ const USER_IDS_CONFIG = {
atype: 1
},

// nextroll
'nextrollId': {
source: 'nextroll.com',
atype: 1
},

// IDx
'idx': {
source: 'idx.lat',
Expand Down
8 changes: 8 additions & 0 deletions modules/userId/eids.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ userIdAsEids = [
}]
},

{
source: 'nextroll.com',
uids: [{
id: 'some-random-id-value',
atype: 1
}]
},

{
source: 'audigent.com',
uids: [{
Expand Down
7 changes: 6 additions & 1 deletion modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ pbjs.setConfig({
expires: 90, // Expiration in days
refreshInSeconds: 8*3600 // User Id cache lifetime in seconds, defaulting to 'expires'
},
}, {
}, {
name: 'nextrollId',
params: {
partnerId: "1009", // Set your real NextRoll partner ID here for production
}
}, {
name: 'criteo',
storage: { // It is best not to specify this parameter since the module needs to be called as many times as possible
type: 'html5',
Expand Down
56 changes: 56 additions & 0 deletions test/spec/modules/nextrollIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { nextrollIdSubmodule, storage } from 'modules/nextrollIdSystem.js';

const LS_VALUE = `{
"AdID":{"id":"adid","key":"AdID"},
"AdID:1002": {"id":"adid","key":"AdID:1002","value":"id_value"}}`;

describe('NextrollId module', function () {
let sandbox = sinon.sandbox.create();
let hasLocalStorageStub;
let getLocalStorageStub;

beforeEach(function() {
hasLocalStorageStub = sandbox.stub(storage, 'hasLocalStorage');
getLocalStorageStub = sandbox.stub(storage, 'getDataFromLocalStorage');
});

afterEach(function () {
sandbox.restore();
})

const testCases = [
{
expect: {
id: {nextrollId: 'id_value'},
},
params: {partnerId: '1002'},
localStorage: LS_VALUE
},
{
expect: {id: undefined},
params: {partnerId: '1003'},
localStorage: LS_VALUE
},
{
expect: {id: undefined},
params: {partnerId: ''},
localStorage: LS_VALUE
},
{
expect: {id: undefined},
params: {partnerId: '102'},
localStorage: undefined
},
{
expect: {id: undefined},
params: undefined,
localStorage: undefined
}
]
testCases.forEach(
(testCase, i) => it(`getId() (TC #${i}) should return the nextroll id if it exists`, function () {
getLocalStorageStub.withArgs('dca0.com').returns(testCase.localStorage);
const id = nextrollIdSubmodule.getId({params: testCase.params});
expect(id).to.be.deep.equal(testCase.expect);
}))
});