-
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.
Adquery ID System: add new ID module (#7852)
* added adqueryID module * Adquery QID module - Added missing files and fixed test Co-authored-by: m.czerwiak <marcin.czerwiak@azagroup.eu>
- Loading branch information
Showing
8 changed files
with
312 additions
and
21 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,103 @@ | ||
/** | ||
* This module adds Adquery QID to the User ID module | ||
* The {@link module:modules/userId} module is required | ||
* @module modules/adqueryIdSystem | ||
* @requires module:modules/userId | ||
*/ | ||
|
||
import {ajax} from '../src/ajax.js'; | ||
import {getStorageManager} from '../src/storageManager.js'; | ||
import {submodule} from '../src/hook.js'; | ||
import * as utils from '../src/utils.js'; | ||
|
||
const MODULE_NAME = 'qid'; | ||
const AU_GVLID = 902; | ||
|
||
export const storage = getStorageManager(AU_GVLID, 'qid'); | ||
|
||
/** | ||
* Param or default. | ||
* @param {String} param | ||
* @param {String} defaultVal | ||
*/ | ||
function paramOrDefault(param, defaultVal, arg) { | ||
if (utils.isFn(param)) { | ||
return param(arg); | ||
} else if (utils.isStr(param)) { | ||
return param; | ||
} | ||
return defaultVal; | ||
} | ||
|
||
/** @type {Submodule} */ | ||
export const adqueryIdSubmodule = { | ||
/** | ||
* used to link submodule with config | ||
* @type {string} | ||
*/ | ||
name: MODULE_NAME, | ||
|
||
/** | ||
* IAB TCF Vendor ID | ||
* @type {string} | ||
*/ | ||
gvlid: AU_GVLID, | ||
|
||
/** | ||
* decode the stored id value for passing to bid requests | ||
* @function | ||
* @param {{value:string}} value | ||
* @returns {{qid:Object}} | ||
*/ | ||
decode(value) { | ||
let qid = storage.getDataFromLocalStorage('qid'); | ||
if (utils.isStr(qid)) { | ||
return {qid: qid}; | ||
} | ||
return (value && typeof value['qid'] === 'string') ? { 'qid': value['qid'] } : undefined; | ||
}, | ||
/** | ||
* performs action to obtain id and return a value in the callback's response argument | ||
* @function | ||
* @param {SubmoduleConfig} [config] | ||
* @returns {IdResponse|undefined} | ||
*/ | ||
getId(config) { | ||
if (!utils.isPlainObject(config.params)) { | ||
config.params = {}; | ||
} | ||
const url = paramOrDefault(config.params.url, | ||
`https://bidder.adquery.io/prebid/qid`, | ||
config.params.urlArg); | ||
|
||
const resp = function (callback) { | ||
let qid = storage.getDataFromLocalStorage('qid'); | ||
if (utils.isStr(qid)) { | ||
const responseObj = {qid: qid}; | ||
callback(responseObj); | ||
} else { | ||
const callbacks = { | ||
success: response => { | ||
let responseObj; | ||
if (response) { | ||
try { | ||
responseObj = JSON.parse(response); | ||
} catch (error) { | ||
utils.logError(error); | ||
} | ||
} | ||
callback(responseObj); | ||
}, | ||
error: error => { | ||
utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); | ||
callback(); | ||
} | ||
}; | ||
ajax(url, callbacks, undefined, {method: 'GET'}); | ||
} | ||
}; | ||
return {callback: resp}; | ||
} | ||
}; | ||
|
||
submodule('userId', adqueryIdSubmodule); |
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,35 @@ | ||
# Adquery QID | ||
|
||
Adquery QID Module. For assistance setting up your module please contact us at [prebid@adquery.io](prebid@adquery.io). | ||
|
||
### Prebid Params | ||
|
||
Individual params may be set for the Adquery ID Submodule. At least one identifier must be set in the params. | ||
|
||
``` | ||
pbjs.setConfig({ | ||
usersync: { | ||
userIds: [{ | ||
name: 'qid', | ||
storage: { | ||
name: 'qid', | ||
type: 'html5' | ||
} | ||
}] | ||
} | ||
}); | ||
``` | ||
## Parameter Descriptions for the `usersync` Configuration Section | ||
The below parameters apply only to the Adquery User ID Module integration. | ||
|
||
| Param under usersync.userIds[] | Scope | Type | Description | Example | | ||
| --- | --- | --- | --- | --- | | ||
| name | Required | String | ID value for the Adquery ID module - `"qid"` | `"qid"` | | ||
| storage | Required | Object | The publisher must specify the local storage in which to store the results of the call to get the user ID. | | | ||
| 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 html5 local storage where the user ID will be stored. | `"qid"` | | ||
| 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 Adquery 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 | `{"qid": "2abf9f001fcd81241b67"}` | | ||
| params | Optional | Object | Used to store params for the id system | | ||
| params.url | Optional | String | Set an alternate GET url for qid with this parameter | | ||
| params.urlArg | Optional | Object | Optional url parameter for params.url | |
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,74 @@ | ||
import { adqueryIdSubmodule, storage } from 'modules/adqueryIdSystem.js'; | ||
import { server } from 'test/mocks/xhr.js'; | ||
import {amxIdSubmodule} from '../../../modules/amxIdSystem'; | ||
import * as utils from '../../../src/utils'; | ||
|
||
const config = { | ||
storage: { | ||
type: 'html5', | ||
}, | ||
}; | ||
|
||
describe('AdqueryIdSystem', function () { | ||
describe('qid submodule', () => { | ||
it('should expose a "name" property containing qid', () => { | ||
expect(adqueryIdSubmodule.name).to.equal('qid'); | ||
}); | ||
|
||
it('should expose a "gvlid" property containing the GVL ID 902', () => { | ||
expect(adqueryIdSubmodule.gvlid).to.equal(902); | ||
}); | ||
}); | ||
|
||
describe('getId', function() { | ||
let getDataFromLocalStorageStub; | ||
|
||
beforeEach(function() { | ||
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); | ||
}); | ||
|
||
afterEach(function () { | ||
getDataFromLocalStorageStub.restore(); | ||
}); | ||
|
||
it('gets a adqueryId', function() { | ||
const config = { | ||
params: {} | ||
}; | ||
const callbackSpy = sinon.spy(); | ||
const callback = adqueryIdSubmodule.getId(config).callback; | ||
callback(callbackSpy); | ||
const request = server.requests[0]; | ||
expect(request.url).to.eq(`https://bidder.adquery.io/prebid/qid`); | ||
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'qid' })); | ||
expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'}); | ||
}); | ||
|
||
it('gets a cached adqueryId', function() { | ||
const config = { | ||
params: {} | ||
}; | ||
getDataFromLocalStorageStub.withArgs('qid').returns('qid'); | ||
|
||
const callbackSpy = sinon.spy(); | ||
const callback = adqueryIdSubmodule.getId(config).callback; | ||
callback(callbackSpy); | ||
expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'}); | ||
}); | ||
|
||
it('allows configurable id url', function() { | ||
const config = { | ||
params: { | ||
url: 'https://bidder.adquery.io' | ||
} | ||
}; | ||
const callbackSpy = sinon.spy(); | ||
const callback = adqueryIdSubmodule.getId(config).callback; | ||
callback(callbackSpy); | ||
const request = server.requests[0]; | ||
expect(request.url).to.eq('https://bidder.adquery.io'); | ||
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'testqid' })); | ||
expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'testqid'}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.