-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admixer ID System: add userId submodule (#6238)
* Migrating to Prebid 1.0 * Migrating to Prebid 1.0 * Fix spec * add gdpr and usp * remove changes in gdpr_hello_world.html * Update gdpr_hello_world.html add spaces * add user syncs * remove comments * tests * admixer id system * admixer id system * admixer id system eids.md userId.md * admixer id system .submodules.json * admixer id system Co-authored-by: atkachov <[email protected]>
- Loading branch information
1 parent
aaa300f
commit c81245c
Showing
7 changed files
with
315 additions
and
31 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* This module adds AdmixerId to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/admixerIdSubmodule | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import * as utils from '../src/utils.js' | ||
import { ajax } from '../src/ajax.js'; | ||
import { submodule } from '../src/hook.js'; | ||
import {getStorageManager} from '../src/storageManager.js'; | ||
|
||
export const storage = getStorageManager(); | ||
|
||
/** @type {Submodule} */ | ||
export const admixerIdSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: 'admixerId', | ||
/** | ||
* used to specify vendor id | ||
* @type {number} | ||
*/ | ||
gvlid: 511, | ||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param {string} value | ||
* @returns {{admixerId:string}} | ||
*/ | ||
decode(value) { | ||
return { 'admixerId': value } | ||
}, | ||
/** | ||
* performs action to obtain id and return a value in the callback's response argument | ||
* @function | ||
* @param {SubmoduleConfig} [config] | ||
* @param {ConsentData} [consentData] | ||
* @returns {IdResponse|undefined} | ||
*/ | ||
getId(config, consentData) { | ||
const {e, p, pid} = (config && config.params) || {}; | ||
if (!pid || typeof pid !== 'string') { | ||
utils.logError('admixerId submodule requires partner id to be defined'); | ||
return; | ||
} | ||
const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; | ||
const consentString = gdpr ? consentData.consentString : ''; | ||
if (gdpr && !consentString) { | ||
utils.logInfo('Consent string is required to call admixer id.'); | ||
return; | ||
} | ||
const url = `https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}${e ? `&e=${e}` : ''}${p ? `&p=${p}` : ''}${consentString ? `&cs=${consentString}` : ''}`; | ||
const resp = function(callback) { | ||
if (window.admixTMLoad && window.admixTMLoad.push) { | ||
window.admixTMLoad.push(function() { | ||
window.admixTM.retrieveVisitorId(function(visitorId) { | ||
if (visitorId) { | ||
callback(visitorId); | ||
} else { | ||
callback(); | ||
} | ||
}); | ||
}); | ||
} else { | ||
retrieveVisitorId(url, callback); | ||
} | ||
}; | ||
|
||
return { callback: resp }; | ||
} | ||
}; | ||
function retrieveVisitorId(url, callback) { | ||
ajax(url, { | ||
success: response => { | ||
const {setData: {visitorid} = {}} = JSON.parse(response || '{}'); | ||
if (visitorid) { | ||
callback(visitorid); | ||
} else { | ||
callback(); | ||
} | ||
}, | ||
error: error => { | ||
utils.logInfo(`admixerId: fetch encountered an error`, error); | ||
callback(); | ||
} | ||
}, undefined, { method: 'GET', withCredentials: true }); | ||
} | ||
|
||
submodule('userId', admixerIdSubmodule); |
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
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,81 @@ | ||
import {admixerIdSubmodule} from 'modules/admixerIdSystem.js'; | ||
import * as utils from 'src/utils.js'; | ||
import {server} from 'test/mocks/xhr.js'; | ||
import {getStorageManager} from '../../../src/storageManager.js'; | ||
|
||
export const storage = getStorageManager(); | ||
|
||
const pid = '4D393FAC-B6BB-4E19-8396-0A4813607316'; | ||
const getIdParams = {params: {pid: pid}}; | ||
describe('admixerId tests', function () { | ||
let logErrorStub; | ||
|
||
beforeEach(function () { | ||
logErrorStub = sinon.stub(utils, 'logError'); | ||
}); | ||
|
||
afterEach(function () { | ||
logErrorStub.restore(); | ||
}); | ||
|
||
it('should log an error if pid configParam was not passed when getId', function () { | ||
admixerIdSubmodule.getId(); | ||
expect(logErrorStub.callCount).to.be.equal(1); | ||
|
||
admixerIdSubmodule.getId({}); | ||
expect(logErrorStub.callCount).to.be.equal(2); | ||
|
||
admixerIdSubmodule.getId({params: {}}); | ||
expect(logErrorStub.callCount).to.be.equal(3); | ||
|
||
admixerIdSubmodule.getId({params: {pid: 123}}); | ||
expect(logErrorStub.callCount).to.be.equal(4); | ||
}); | ||
|
||
it('should NOT call the admixer id endpoint if gdpr applies but consent string is missing', function () { | ||
let submoduleCallback = admixerIdSubmodule.getId(getIdParams, { gdprApplies: true }); | ||
expect(submoduleCallback).to.be.undefined; | ||
}); | ||
|
||
it('should call the admixer id endpoint', function () { | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = admixerIdSubmodule.getId(getIdParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}`); | ||
request.respond( | ||
200, | ||
{}, | ||
JSON.stringify({}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should call callback with user id', function () { | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = admixerIdSubmodule.getId(getIdParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}`); | ||
request.respond( | ||
200, | ||
{}, | ||
JSON.stringify({setData: {visitorid: '571058d70bce453b80e6d98b4f8a81e3'}}) | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
expect(callBackSpy.args[0][0]).to.be.eq('571058d70bce453b80e6d98b4f8a81e3'); | ||
}); | ||
|
||
it('should continue to callback if ajax response 204', function () { | ||
let callBackSpy = sinon.spy(); | ||
let submoduleCallback = admixerIdSubmodule.getId(getIdParams).callback; | ||
submoduleCallback(callBackSpy); | ||
let request = server.requests[0]; | ||
expect(request.url).to.be.eq(`https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}`); | ||
request.respond( | ||
204 | ||
); | ||
expect(callBackSpy.calledOnce).to.be.true; | ||
expect(callBackSpy.args[0][0]).to.be.undefined; | ||
}); | ||
}); |
Oops, something went wrong.