diff --git a/modules/consentManagementUsp.js b/modules/consentManagementUsp.js index a210132947c..2421b5e99e5 100644 --- a/modules/consentManagementUsp.js +++ b/modules/consentManagementUsp.js @@ -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 @@ -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); } diff --git a/test/spec/modules/consentManagementUsp_spec.js b/test/spec/modules/consentManagementUsp_spec.js index d757ea0b86f..05f98d1c6a3 100644 --- a/test/spec/modules/consentManagementUsp_spec.js +++ b/test/spec/modules/consentManagementUsp_spec.js @@ -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'; @@ -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 () {