-
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
PAIR: Support for Generic TechLab Version #12146 #12599
Open
therevoltingx
wants to merge
2
commits into
prebid:master
Choose a base branch
from
InteractiveAdvertisingBureau:feature/adds-generic-pair
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* This module adds Open PAIR Id to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/openPairIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import {submodule} from '../src/hook.js'; | ||
import {getStorageManager} from '../src/storageManager.js' | ||
import {logInfo} from '../src/utils.js'; | ||
import {MODULE_TYPE_UID} from '../src/activities/modules.js'; | ||
import {VENDORLESS_GVLID} from '../src/consentHandler.js'; | ||
|
||
/** | ||
* @typedef {import('../modules/userId/index.js').Submodule} Submodule | ||
*/ | ||
|
||
const MODULE_NAME = 'openPairId'; | ||
const DEFAULT_PUBLISHER_ID_KEY = 'pairId'; | ||
|
||
const DEFAULT_STORAGE_PUBLISHER_ID_KEYS = { | ||
liveramp: '_lr_pairId' | ||
}; | ||
|
||
export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME}); | ||
|
||
function publisherIdFromLocalStorage(key) { | ||
return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(key) : null; | ||
} | ||
|
||
function publisherIdFromCookie(key) { | ||
return storage.cookiesAreEnabled() ? storage.getCookie(key) : null; | ||
} | ||
|
||
/** @type {Submodule} */ | ||
export const openPairIdSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: MODULE_NAME, | ||
/** | ||
* used to specify vendor id | ||
* @type {number} | ||
*/ | ||
gvlid: VENDORLESS_GVLID, | ||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param { string | undefined } value | ||
* @returns {{pairId:string} | undefined } | ||
*/ | ||
decode(value) { | ||
return value && Array.isArray(value) ? {'openPairId': value} : undefined; | ||
}, | ||
/** | ||
* Performs action to obtain ID and return a value in the callback's response argument. | ||
* @function getId | ||
* @param {Object} config - The configuration object. | ||
* @param {Object} config.params - The parameters from the configuration. | ||
* @returns {{id: string[] | undefined}} The obtained IDs or undefined if no IDs are found. | ||
*/ | ||
getId(config) { | ||
const publisherIdsString = publisherIdFromLocalStorage(DEFAULT_PUBLISHER_ID_KEY) || publisherIdFromCookie(DEFAULT_PUBLISHER_ID_KEY); | ||
let ids = [] | ||
|
||
if (publisherIdsString && typeof publisherIdsString == 'string') { | ||
try { | ||
ids = ids.concat(JSON.parse(atob(publisherIdsString))) | ||
} catch (error) { | ||
logInfo(error) | ||
} | ||
} | ||
|
||
const configParams = (config && config.params) ? config.params : {}; | ||
const cleanRooms = Object.keys(configParams); | ||
|
||
for (let i = 0; i < cleanRooms.length; i++) { | ||
const cleanRoom = cleanRooms[i]; | ||
const cleanRoomParams = configParams[cleanRoom]; | ||
|
||
const cleanRoomStorageLocation = cleanRoomParams.storageKey || DEFAULT_STORAGE_PUBLISHER_ID_KEYS[cleanRoom]; | ||
const cleanRoomValue = publisherIdFromLocalStorage(cleanRoomStorageLocation) || publisherIdFromCookie(cleanRoomStorageLocation); | ||
|
||
if (cleanRoomValue) { | ||
try { | ||
const parsedValue = atob(cleanRoomValue); | ||
|
||
if (parsedValue) { | ||
const obj = JSON.parse(parsedValue); | ||
|
||
if (obj && typeof obj === 'object' && obj.envelope) { | ||
ids = ids.concat(obj.envelope); | ||
} else { | ||
logInfo('Open Pair ID: Parsed object is not valid or does not contain envelope'); | ||
} | ||
} else { | ||
logInfo('Open Pair ID: Decoded value is empty'); | ||
} | ||
} catch (error) { | ||
logInfo('Open Pair ID: Error parsing JSON: ', error); | ||
} | ||
} else { | ||
logInfo('Open Pair ID: data clean room value for pairId from storage is empty or null'); | ||
} | ||
} | ||
|
||
if (ids.length == 0) { | ||
logInfo('Open Pair ID: no ids found') | ||
return undefined; | ||
} | ||
|
||
return {'id': ids}; | ||
}, | ||
eids: { | ||
'openPairId': { | ||
source: 'pair-protocol.com', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .org? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shailley decided to go with .com for now |
||
atype: 3 | ||
}, | ||
} | ||
}; | ||
|
||
submodule('userId', openPairIdSubmodule); |
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,114 @@ | ||
import { storage, submodule } from 'modules/openPairIdSystem.js'; | ||
import * as utils from 'src/utils.js'; | ||
|
||
describe('openPairId', function () { | ||
let sandbox; | ||
let logInfoStub; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
logInfoStub = sandbox.stub(utils, 'logInfo'); | ||
}); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('should read publisher id from specified clean room if configured with storageKey', function() { | ||
let publisherIds = ['test-pair-id1', 'test-pair-id2', 'test-pair-id3']; | ||
sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('habu_pairId_custom').returns(btoa(JSON.stringify({'envelope': publisherIds}))); | ||
|
||
let id = submodule.getId({ | ||
params: { | ||
habu: { | ||
storageKey: 'habu_pairId_custom' | ||
} | ||
}}) | ||
|
||
expect(id).to.be.deep.equal({id: publisherIds}); | ||
}); | ||
|
||
it('should read publisher id from liveramp with default storageKey and additional clean room with configured storageKey', function() { | ||
let getDataStub = sandbox.stub(storage, 'getDataFromLocalStorage'); | ||
let liveRampPublisherIds = ['lr-test-pair-id1', 'lr-test-pair-id2', 'lr-test-pair-id3']; | ||
getDataStub.withArgs('_lr_pairId').returns(btoa(JSON.stringify({'envelope': liveRampPublisherIds}))); | ||
|
||
let habuPublisherIds = ['habu-test-pair-id1', 'habu-test-pair-id2', 'habu-test-pair-id3']; | ||
getDataStub.withArgs('habu_pairId_custom').returns(btoa(JSON.stringify({'envelope': habuPublisherIds}))); | ||
|
||
let id = submodule.getId({ | ||
params: { | ||
habu: { | ||
storageKey: 'habu_pairId_custom' | ||
}, | ||
liveramp: {} | ||
}}) | ||
|
||
expect(id).to.be.deep.equal({id: habuPublisherIds.concat(liveRampPublisherIds)}); | ||
}); | ||
|
||
it('should log an error if no ID is found when getId', function() { | ||
submodule.getId({ params: {} }); | ||
expect(logInfoStub.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should read publisher id from local storage if exists', function() { | ||
let publisherIds = ['test-pair-id1', 'test-pair-id2', 'test-pair-id3']; | ||
sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('pairId').returns(btoa(JSON.stringify(pairIds))); | ||
|
||
let id = submodule.getId({ params: {} }); | ||
expect(id).to.be.deep.equal({id: publisherIds}); | ||
}); | ||
|
||
it('should read publisher id from cookie if exists', function() { | ||
let publisherIds = ['test-pair-id4', 'test-pair-id5', 'test-pair-id6']; | ||
sandbox.stub(storage, 'getCookie').withArgs('pairId').returns(btoa(JSON.stringify(pairIds))); | ||
|
||
let id = submodule.getId({ params: {} }); | ||
expect(id).to.be.deep.equal({id: publisherIds}); | ||
}); | ||
|
||
it('should read publisher id from default liveramp envelope local storage key if configured', function() { | ||
let publisherIds = ['test-pair-id1', 'test-pair-id2', 'test-pair-id3']; | ||
sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('_lr_pairId').returns(btoa(JSON.stringify({'envelope': publisherIds}))); | ||
let id = submodule.getId({ | ||
params: { | ||
liveramp: {} | ||
}}) | ||
expect(id).to.be.deep.equal({id: publisherIds}) | ||
}); | ||
|
||
it('should read publisher id from default liveramp envelope cookie entry if configured', function() { | ||
let publisherIds = ['test-pair-id4', 'test-pair-id5', 'test-pair-id6']; | ||
sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('_lr_pairId').returns(btoa(JSON.stringify({'envelope': publisherIds}))); | ||
let id = submodule.getId({ | ||
params: { | ||
liveramp: {} | ||
}}) | ||
expect(id).to.be.deep.equal({id: publisherIds}) | ||
}); | ||
|
||
it('should read publisher id from specified liveramp envelope cookie entry if configured with storageKey', function() { | ||
let publisherIds = ['test-pair-id7', 'test-pair-id8', 'test-pair-id9']; | ||
sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('lr_pairId_custom').returns(btoa(JSON.stringify({'envelope': publisherIds}))); | ||
let id = submodule.getId({ | ||
params: { | ||
liveramp: { | ||
storageKey: 'lr_pairId_custom' | ||
} | ||
}}) | ||
expect(id).to.be.deep.equal({id: publisherIds}) | ||
}); | ||
|
||
it('should not get data from storage if local storage and cookies are disabled', function () { | ||
sandbox.stub(storage, 'localStorageIsEnabled').returns(false); | ||
sandbox.stub(storage, 'cookiesAreEnabled').returns(false); | ||
let id = submodule.getId({ | ||
params: { | ||
liveramp: { | ||
storageKey: 'lr_pairId_custom' | ||
} | ||
} | ||
}) | ||
expect(id).to.equal(undefined) | ||
}); | ||
}); |
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.
I think this requires some more logic to be converted into an EID - the userId module expects a string either from
decode
, or fromeids.openPairId.getValue(id)
eids.pairId.getValue(id)
(because that's what referenced indecode
- see other comment below)From my testing (putting some random data in local storage), this does not generate any EID.
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.
Seems that other modules return a hash in this format, including the original pairId and a few other examples:
Prebid.js/modules/pairIdSystem.js
Line 101 in 2f713dd
Prebid.js/modules/pubProvidedIdSystem.js
Line 56 in 2f713dd
Prebid.js/modules/sharedIdSystem.js
Line 141 in 2f713dd
Prebid.js/modules/publinkIdSystem.js
Line 155 in 2f713dd
I think your test was failing because I was not properly exporting the correct module. Do you mind testing again?