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

ID5 User ID Module: pass a flag back to id5 servers if abTesting was enabled #6170

Merged
Merged
Changes from 1 commit
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
Next Next commit
pass a flag back to ID5 servers if abTesting was enabled by the publi…
…sher for monitoring usage of the feature
  • Loading branch information
smenzer committed Jan 6, 2021
commit 014f8adb070f82e7305f929d95db26041613b782
16 changes: 15 additions & 1 deletion modules/id5IdSystem.js
Original file line number Diff line number Diff line change
@@ -57,7 +57,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 &&
@@ -129,6 +129,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 => {
@@ -278,4 +282,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
@@ -236,6 +236,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));
});
});

describe('Request Bids Hook', function() {