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

Add static API option to the consentManagementUsp module. #4685

Merged
merged 3 commits into from
Jan 7, 2020
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
22 changes: 21 additions & 1 deletion modules/consentManagementUsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ const USPAPI_VERSION = 1;

export let consentAPI;
export let consentTimeout;
export let staticConsentData;

let consentData;
let addedConsentHook = false;

// consent APIs
const uspCallMap = {
'iab': lookupUspConsent
'iab': lookupUspConsent,
'static': lookupStaticConsentData
};

/**
* This function reads the consent string from the config to obtain the consent information of the user.
* @param {function(string)} cmpSuccess acts as a success callback when the value is read from config; pass along consentObject (string) from CMP
* @param {function(string)} cmpError acts as an error callback while interacting with the config string; pass along an error message (string)
* @param {object} hookConfig contains module related variables (see comment in requestBidsHook function)
*/
function lookupStaticConsentData(cmpSuccess, cmpError, hookConfig) {
cmpSuccess(staticConsentData, hookConfig);
}

/**
* This function handles interacting with an USP compliant consent manager to obtain the consent information of the user.
* Given the async nature of the USP's API, we pass in acting success/error callback functions to exit this function
Expand Down Expand Up @@ -283,6 +295,14 @@ export function setConsentConfig(config) {

utils.logInfo('USPAPI consentManagement module has been activated...');

if (consentAPI === 'static') {
if (utils.isPlainObject(config.consentData) && utils.isPlainObject(config.consentData.getUSPData)) {
if (config.consentData.getUSPData.uspString) staticConsentData = { usPrivacy: config.consentData.getUSPData.uspString };
consentTimeout = 0;
} else {
utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`);
}
}
if (!addedConsentHook) {
$$PREBID_GLOBAL$$.requestBids.before(requestBidsHook, 50);
}
Expand Down
28 changes: 27 additions & 1 deletion test/spec/modules/consentManagementUsp_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
requestBidsHook,
resetConsentData,
consentAPI,
consentTimeout
consentTimeout,
staticConsentData
} from 'modules/consentManagementUsp';
import * as utils from 'src/utils';
import { config } from 'src/config';
Expand Down Expand Up @@ -84,6 +85,31 @@ describe('consentManagement', function () {
expect(consentTimeout).to.be.equal(7500);
});
});

describe('static consent string setConsentConfig value', () => {
afterEach(() => {
config.resetConfig();
$$PREBID_GLOBAL$$.requestBids.removeAll();
});
it('results in user settings overriding system defaults', () => {
let staticConfig = {
usp: {
cmpApi: 'static',
timeout: 7500,
consentData: {
getUSPData: {
uspString: '1YYY'
}
}
}
};

setConsentConfig(staticConfig);
expect(consentAPI).to.be.equal('static');
expect(consentTimeout).to.be.equal(0); // should always return without a timeout when config is used
expect(staticConsentData.usPrivacy).to.be.equal(staticConfig.usp.consentData.getUSPData.uspString);
});
});
});

describe('requestBidsHook tests:', function () {
Expand Down