Skip to content

Commit

Permalink
Add static API option to the consentManagementUsp module. (#4685) (#4705
Browse files Browse the repository at this point in the history
)

* Add static API option to the consentManagementUsp module.

The GDPR consent management module has a static configuration option. This change adds "static" as an API option to the consentManagementUsp module.

* Added a unit test for the static API option in the consentManagementUsp module.

* Updated the consentManagementUsp module static API config object to follow the recommended format.
  • Loading branch information
harpere authored Jan 8, 2020
1 parent f07c61d commit 5f51fb3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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

0 comments on commit 5f51fb3

Please sign in to comment.