-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 britepool userid submodule #4314
Merged
jsnellbaker
merged 37 commits into
prebid:master
from
britepool:Add-britepool-userid-submodule
Dec 4, 2019
Merged
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
19770e5
* Added BritePool User ID Submodule
cd5e4ce
* Refactor getId() and allow it to return a sync value from getter()
cfaherty 7716089
* Pull only primaryBPID key out of hardened API response
cfaherty 84b6e09
Merge branch 'master' of github.com:britepool/Prebid.js into Add-brit…
cfaherty 0fd8701
add check for decoded primaryBPID value and update readme
a01dc6a
* Added BritePool User ID Submodule
fda9572
* Refactor getId() and allow it to return a sync value from getter()
cfaherty 389597d
* Pull only primaryBPID key out of hardened API response
cfaherty 249e415
add check for decoded primaryBPID value and update readme
ce5de3e
update userId_spec.js tests
05c90d2
update userId_spec.js tests and add britepoolIdSystem to submodules.json
44266b8
Merge remote-tracking branch 'origin/Add-britepool-userid-submodule' …
85c7235
moved our module specific tests to own spec file
cd71ee7
* Update to use getId() with callback key
0d11278
* Revert comment to "Use existing cookie"
21a3faa
add support for prebid server
e034cfb
Merge branch 'master' into Add-britepool-userid-submodule
0d74136
Merge branch 'master' into Add-britepool-userid-submodule
e69afe5
add comma back to submodules.json
4dc9ec1
Merge branch 'master' into Add-britepool-userid-submodule
2f75ae6
updating markdown for email address
b5a23f6
Merge branch 'master' into Add-britepool-userid-submodule
b2185c4
Merge branch 'master' into Add-britepool-userid-submodule
6c6811d
Merge branch 'master' into Add-britepool-userid-submodule
19810a2
* Allow the britepool call without parameters (identifiers)
1c18309
fixed merging error of double ||
ed91dc4
* Fix the immediate value response to be in id key
9562f70
Merge pull request #1 from britepool/Allow-britepool-call-without-params
cfaherty 1e21e30
* Fixed test which was expecting id key
9ed4f25
Merge branch 'master' into Add-britepool-userid-submodule
370bbeb
* Touch
411dbbf
* Update doc
dc5049c
* Suggested changes to move britepoolIdSystem out of userId default
c83f059
Merge pull request #2 from britepool/britepool-26-changes
cfaherty 9b7add2
Merge branch 'master' into Add-britepool-userid-submodule
f5d20ac
* Change weird backticks to single quotes
6789af4
* Added functional identifiers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* This module adds BritePoolId to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/britepoolIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import * as utils from '../../src/utils' | ||
import {ajax} from '../../src/ajax'; | ||
|
||
/** @type {Submodule} */ | ||
export const britepoolIdSubmodule = { | ||
/** | ||
* Used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'britepoolId', | ||
/** | ||
* Decode the stored id value for passing to bid requests | ||
* @function | ||
* @param {string} value | ||
* @returns {{britepoolid:string}} | ||
*/ | ||
decode(value) { | ||
return (value && typeof value['primaryBPID'] === 'string') ? { 'britepoolid': value['primaryBPID'] } : null; | ||
}, | ||
/** | ||
* Performs action to obtain id and return a value in the callback's response argument | ||
* @function | ||
* @param {SubmoduleParams} [configParams] | ||
* @returns {function(callback:function)} | ||
*/ | ||
getId(submoduleConfigParams, consentData) { | ||
const { params, headers, url, getter, errors } = britepoolIdSubmodule.createParams(submoduleConfigParams, consentData); | ||
let getterResponse = null; | ||
if (typeof getter === 'function') { | ||
getterResponse = getter(params); | ||
// First let's rule out that the response is not a function | ||
if (typeof getterResponse !== 'function') { | ||
// Optimization to return value from getter | ||
return { | ||
id: britepoolIdSubmodule.normalizeValue(getterResponse) | ||
}; | ||
} | ||
} | ||
// Return for async operation | ||
return { | ||
callback: function(callback) { | ||
if (errors.length > 0) { | ||
errors.forEach(error => utils.logError(error)); | ||
callback(); | ||
return; | ||
} | ||
if (getterResponse) { | ||
// Resolve the getter function response | ||
try { | ||
getterResponse(function(response) { | ||
callback(britepoolIdSubmodule.normalizeValue(response)); | ||
}); | ||
} catch (error) { | ||
if (error !== '') utils.logError(error); | ||
callback(); | ||
} | ||
} else { | ||
ajax(url, { | ||
success: response => { | ||
const responseObj = britepoolIdSubmodule.normalizeValue(response); | ||
callback(responseObj ? { primaryBPID: responseObj.primaryBPID } : null); | ||
}, | ||
error: error => { | ||
if (error !== '') utils.logError(error); | ||
callback(); | ||
} | ||
}, JSON.stringify(params), { customHeaders: headers, contentType: 'application/json', method: 'POST', withCredentials: true }); | ||
} | ||
} | ||
} | ||
}, | ||
/** | ||
* Helper method to create params for our API call | ||
* @param {SubmoduleParams} [configParams] | ||
* @returns {object} Object with parsed out params | ||
*/ | ||
createParams(submoduleConfigParams, consentData) { | ||
let errors = []; | ||
const headers = {}; | ||
let params = Object.assign({}, submoduleConfigParams); | ||
if (params.getter) { | ||
// Custom getter will not require other params | ||
if (typeof params.getter !== 'function') { | ||
errors.push(`${MODULE_NAME} - britepoolId submodule requires getter to be a function`); | ||
return { errors }; | ||
} | ||
} else { | ||
if (params.api_key) { | ||
// Add x-api-key into the header | ||
headers['x-api-key'] = params.api_key; | ||
} | ||
} | ||
const url = params.url || 'https://api.britepool.com/v1/britepool/id'; | ||
const getter = params.getter; | ||
delete params.api_key; | ||
delete params.url; | ||
delete params.getter; | ||
return { | ||
params, | ||
headers, | ||
url, | ||
getter, | ||
errors | ||
}; | ||
}, | ||
/** | ||
* Helper method to normalize a JSON value | ||
*/ | ||
normalizeValue(value) { | ||
let valueObj = null; | ||
if (typeof value === 'object') { | ||
valueObj = value; | ||
} else if (typeof value === 'string') { | ||
try { | ||
valueObj = JSON.parse(value); | ||
} catch (error) { | ||
utils.logError(error); | ||
} | ||
} | ||
return valueObj; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## BritePool User ID Submodule | ||
|
||
BritePool User ID Module. For assistance setting up your module please contact us at [[email protected]]([email protected]). | ||
|
||
### Prebid Params | ||
|
||
Individual params may be set for the BritePool User ID Submodule. At least one identifier must be set in the params. | ||
``` | ||
pbjs.setConfig({ | ||
usersync: { | ||
userIds: [{ | ||
name: ’britepoolId’, | ||
storage: { | ||
name: ‘britepoolid’, | ||
type: ‘cookie’, | ||
expires: 30 | ||
}, | ||
params: { | ||
url: 'https://sandbox-api.britepool.com/v1/britepool/id', // optional | ||
api_key: ’xxx’, // provided by britepool | ||
hash: ’yyyy’, // example identifier | ||
ssid: 'r894hvfnviurfincdejkencjcv' // example identifier | ||
} | ||
}] | ||
} | ||
}); | ||
``` | ||
## Parameter Descriptions for the `usersync` Configuration Section | ||
The below parameters apply only to the BritePool User ID Module integration. | ||
|
||
| Param under usersync.userIds[] | Scope | Type | Description | Example | | ||
| --- | --- | --- | --- | --- | | ||
| name | Required | String | ID value for the BritePool module - `"britepoolId"` | `"britepoolId"` | | ||
| params | Required | Object | Details for BritePool initialization. | | | ||
| params.api_key | Required | String |BritePool API Key provided by BritePool | "458frgde-djd7-3ert-gyhu-12fghy76dnmko" | | ||
| params.url | Optional | String |BritePool API url | "https://sandbox-api.britepool.com/v1/britepool/id" | | ||
| params.identifier | Required | String | Where identifier in the params object is the key name. At least one identifier is required. Available Identifiers `aaid` `dtid` `idfa` `ilid` `luid` `mmid` `msid` `mwid` `rida` `ssid` `hash` | `params.ssid` `params.aaid` | | ||
| storage | Required | Object | The publisher must specify the local storage in which to store the results of the call to get the user ID. This can be either cookie or HTML5 storage. | | | ||
| storage.type | Required | String | This is where the results of the user ID will be stored. The recommended method is `localStorage` by specifying `html5`. | `"html5"` | | ||
| storage.name | Required | String | The name of the cookie or html5 local storage where the user ID will be stored. | `"britepoolid"` | | ||
| storage.expires | Optional | Integer | How long (in days) the user ID information will be stored. | `365` | | ||
| value | Optional | Object | Used only if the page has a separate mechanism for storing the BritePool ID. The value is an object containing the values to be sent to the adapters. In this scenario, no URL is called and nothing is added to local storage | `{"primaryBPID": "fd56yui-dvff-v5gbgtgg-4t55-45fggtgt5ttv"}` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect } from 'chai'; | ||
import {britepoolIdSubmodule} from 'modules/userId/britepoolIdSystem'; | ||
|
||
describe('BritePool Submodule', () => { | ||
const api_key = '1111'; | ||
const aaid = '4421ea96-34a9-45df-a4ea-3c41a48a18b1'; | ||
const idfa = '2d1c4fac-5507-4e28-991c-ca544e992dba'; | ||
const bpid = '279c0161-5152-487f-809e-05d7f7e653fd'; | ||
const url_override = 'https://override'; | ||
const getter_override = function(params) { | ||
return JSON.stringify({ 'primaryBPID': bpid }); | ||
}; | ||
const getter_callback_override = function(params) { | ||
return callback => { | ||
callback(JSON.stringify({ 'primaryBPID': bpid })); | ||
}; | ||
}; | ||
|
||
it('sends x-api-key in header and one identifier', () => { | ||
const { params, headers, url, errors } = britepoolIdSubmodule.createParams({ api_key, aaid }); | ||
assert(errors.length === 0, errors); | ||
expect(headers['x-api-key']).to.equal(api_key); | ||
expect(params).to.eql({ aaid }); | ||
}); | ||
|
||
it('sends x-api-key in header and two identifiers', () => { | ||
const { params, headers, url, errors } = britepoolIdSubmodule.createParams({ api_key, aaid, idfa }); | ||
assert(errors.length === 0, errors); | ||
expect(headers['x-api-key']).to.equal(api_key); | ||
expect(params).to.eql({ aaid, idfa }); | ||
}); | ||
|
||
it('allows call without api_key', () => { | ||
const { params, headers, url, errors } = britepoolIdSubmodule.createParams({ aaid, idfa }); | ||
expect(params).to.eql({ aaid, idfa }); | ||
expect(errors.length).to.equal(0); | ||
}); | ||
|
||
it('test url override', () => { | ||
const { params, headers, url, errors } = britepoolIdSubmodule.createParams({ api_key, aaid, url: url_override }); | ||
expect(url).to.equal(url_override); | ||
// Making sure it did not become part of params | ||
expect(params.url).to.be.undefined; | ||
}); | ||
|
||
it('test getter override with value', () => { | ||
const { params, headers, url, getter, errors } = britepoolIdSubmodule.createParams({ api_key, aaid, url: url_override, getter: getter_override }); | ||
expect(getter).to.equal(getter_override); | ||
// Making sure it did not become part of params | ||
expect(params.getter).to.be.undefined; | ||
const response = britepoolIdSubmodule.getId({ api_key, aaid, url: url_override, getter: getter_override }); | ||
assert.deepEqual(response, { id: { 'primaryBPID': bpid } }); | ||
}); | ||
|
||
it('test getter override with callback', done => { | ||
const { params, headers, url, getter, errors } = britepoolIdSubmodule.createParams({ api_key, aaid, url: url_override, getter: getter_callback_override }); | ||
expect(getter).to.equal(getter_callback_override); | ||
// Making sure it did not become part of params | ||
expect(params.getter).to.be.undefined; | ||
const response = britepoolIdSubmodule.getId({ api_key, aaid, url: url_override, getter: getter_callback_override }); | ||
expect(response.callback).to.not.be.undefined; | ||
response.callback(result => { | ||
assert.deepEqual(result, { 'primaryBPID': bpid }); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note in PreBid 3.0 unifiedId, and pubCommonId will be separate modules not installed by default with user ID module itself. Please remove the default installation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi. I've moved our module out of the default installation.