Skip to content

Commit

Permalink
pass a flag back to ID5 servers if abTesting was enabled by the publi…
Browse files Browse the repository at this point in the history
…sher for monitoring usage of the feature (prebid#6170)
  • Loading branch information
smenzer authored and icflournoy committed Feb 5, 2021
1 parent 28e1b93 commit f1002bc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
16 changes: 15 additions & 1 deletion modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const id5IdSubmodule = {
}

// check for A/B testing configuration and hide ID if in Control Group
let abConfig = (config && config.params && config.params.abTesting) || { enabled: false };
let abConfig = getAbTestingConfig(config);
let controlGroup = false;
if (
abConfig.enabled === true &&
Expand Down Expand Up @@ -130,6 +130,10 @@ export const id5IdSubmodule = {
'v': '$prebid.version$'
};

if (getAbTestingConfig(config).enabled === true) {
utils.deepSetValue(data, 'features.ab', 1);
}

const resp = function (callback) {
const callbacks = {
success: response => {
Expand Down Expand Up @@ -282,4 +286,14 @@ export function storeInLocalStorage(key, value, expDays) {
storage.setDataInLocalStorage(`${key}`, value);
}

/**
* gets the existing abTesting config or generates a default config with abTesting off
*
* @param {SubmoduleConfig|undefined} config
* @returns {(Object|undefined)}
*/
function getAbTestingConfig(config) {
return (config && config.params && config.params.abTesting) || { enabled: false };
}

submodule('userId', id5IdSubmodule);
41 changes: 41 additions & 0 deletions test/spec/modules/id5IdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,47 @@ describe('ID5 ID System', function() {
expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(0);
});

it('should call the ID5 server with ab feature = 1 when abTesting is turned on', function () {
let id5Config = getId5FetchConfig();
id5Config.params.abTesting = { enabled: true, controlGroupPct: 10 }

let submoduleCallback = id5IdSubmodule.getId(id5Config, undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];
let requestBody = JSON.parse(request.requestBody);
expect(requestBody.features.ab).to.eq(1);

request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));
});

it('should call the ID5 server without ab feature when abTesting is turned off', function () {
let id5Config = getId5FetchConfig();
id5Config.params.abTesting = { enabled: false, controlGroupPct: 10 }

let submoduleCallback = id5IdSubmodule.getId(id5Config, undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];
let requestBody = JSON.parse(request.requestBody);
expect(requestBody.features).to.be.undefined;

request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));
});

it('should call the ID5 server without ab feature when when abTesting is not set', function () {
let id5Config = getId5FetchConfig();

let submoduleCallback = id5IdSubmodule.getId(id5Config, undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);

let request = server.requests[0];
let requestBody = JSON.parse(request.requestBody);
expect(requestBody.features).to.be.undefined;

request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));
});

it('should store the privacy object from the ID5 server response', function () {
let submoduleCallback = id5IdSubmodule.getId(getId5FetchConfig(), undefined, ID5_STORED_OBJ).callback;
submoduleCallback(callbackSpy);
Expand Down

0 comments on commit f1002bc

Please sign in to comment.