From d997eed00e228c506cb43ed3d2aee833dbfd60da Mon Sep 17 00:00:00 2001 From: Darcy Birkbeck Date: Wed, 1 Jan 2020 23:47:23 -0700 Subject: [PATCH 1/3] 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. --- modules/consentManagementUsp.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/consentManagementUsp.js b/modules/consentManagementUsp.js index a210132947c..c6835068f86 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)) { + staticConsentData = config.consentData; + 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); } From 67838624d25faf3145602511a57b17c3f37d93f3 Mon Sep 17 00:00:00 2001 From: Darcy Birkbeck Date: Thu, 2 Jan 2020 21:00:43 -0700 Subject: [PATCH 2/3] Added a unit test for the static API option in the consentManagementUsp module. --- .../spec/modules/consentManagementUsp_spec.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/consentManagementUsp_spec.js b/test/spec/modules/consentManagementUsp_spec.js index d757ea0b86f..0dfa7aa04ff 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,29 @@ 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: { + 'usPrivacy': '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).to.be.equal(staticConfig.usp.consentData); + }); + }); }); describe('requestBidsHook tests:', function () { From acf93b57cab9161af2cb0d7a644458aac9bb78e9 Mon Sep 17 00:00:00 2001 From: Darcy Birkbeck Date: Sat, 4 Jan 2020 11:30:43 -0700 Subject: [PATCH 3/3] Updated the consentManagementUsp module static API config object to follow the recommended format. --- modules/consentManagementUsp.js | 4 ++-- test/spec/modules/consentManagementUsp_spec.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/consentManagementUsp.js b/modules/consentManagementUsp.js index c6835068f86..2421b5e99e5 100644 --- a/modules/consentManagementUsp.js +++ b/modules/consentManagementUsp.js @@ -296,8 +296,8 @@ export function setConsentConfig(config) { utils.logInfo('USPAPI consentManagement module has been activated...'); if (consentAPI === 'static') { - if (utils.isPlainObject(config.consentData)) { - staticConsentData = config.consentData; + 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.`); diff --git a/test/spec/modules/consentManagementUsp_spec.js b/test/spec/modules/consentManagementUsp_spec.js index 0dfa7aa04ff..05f98d1c6a3 100644 --- a/test/spec/modules/consentManagementUsp_spec.js +++ b/test/spec/modules/consentManagementUsp_spec.js @@ -93,11 +93,13 @@ describe('consentManagement', function () { }); it('results in user settings overriding system defaults', () => { let staticConfig = { - usp: { + usp: { cmpApi: 'static', timeout: 7500, consentData: { - 'usPrivacy': '1YYY' + getUSPData: { + uspString: '1YYY' + } } } }; @@ -105,7 +107,7 @@ describe('consentManagement', function () { 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).to.be.equal(staticConfig.usp.consentData); + expect(staticConsentData.usPrivacy).to.be.equal(staticConfig.usp.consentData.getUSPData.uspString); }); }); });