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
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
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