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

Adquery ID System: add new ID module #7852

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"uid2IdSystem",
"unifiedIdSystem",
"verizonMediaIdSystem",
"zeotapIdPlusIdSystem"
"zeotapIdPlusIdSystem",
"adqueryIdSystem"
],
"adpod": [
"freeWheelAdserverVideo",
Expand Down
103 changes: 103 additions & 0 deletions modules/adqueryIdSystem.js
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);
35 changes: 35 additions & 0 deletions modules/adqueryIdSystem.md
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 |
8 changes: 7 additions & 1 deletion modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ const USER_IDS_CONFIG = {
'connectId': {
source: 'yahoo.com',
atype: 3
}
},

// Adquery ID
'qid': {
source: 'adquery.io',
atype: 1
},
};

// this function will create an eid object for the given UserId sub-module
Expand Down
8 changes: 8 additions & 0 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ pbjs.setConfig({
type: 'html5',
expires: 15
}
}
{
name: "qid",
storage: {
type: "html5",
name: "qid",
expires: 365
}
}],
syncDelay: 5000
}
Expand Down
74 changes: 74 additions & 0 deletions test/spec/modules/adqueryIdSystem_spec.js
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'});
});
});
});
15 changes: 15 additions & 0 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});

it('qid', function() {
const userId = {
qid: 'some-random-id-value'
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(1);
expect(newEids[0]).to.deep.equal({
source: 'adquery.io',
uids: [{
id: 'some-random-id-value',
atype: 1
}]
});
});
});
describe('Negative case', function() {
it('eids array generation for UN-known sub-module', function() {
Expand Down
Loading