Skip to content

Commit

Permalink
Ability to statically pass consentData (#2636)
Browse files Browse the repository at this point in the history
* Added static consentData to consentManagement config

* Added test for static cmpApi

* logError instead of logInfo
  • Loading branch information
ptomasroos authored and jsnellbaker committed Sep 10, 2018
1 parent b1e7843 commit 6a3d628
Show file tree
Hide file tree
Showing 2 changed files with 433 additions and 2 deletions.
24 changes: 23 additions & 1 deletion modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ const DEFAULT_ALLOW_AUCTION_WO_CONSENT = true;
export let userCMP;
export let consentTimeout;
export let allowAuction;
export let staticConsentData;

let consentData;

// add new CMPs here, with their dedicated lookup function
const cmpCallMap = {
'iab': lookupIabConsent
'iab': lookupIabConsent,
'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 IAB compliant CMP to obtain the consent information of the user.
* Given the async nature of the CMP's API, we pass in acting success/error callback functions to exit this function
Expand Down Expand Up @@ -348,7 +360,17 @@ export function setConfig(config) {
allowAuction = DEFAULT_ALLOW_AUCTION_WO_CONSENT;
utils.logInfo(`consentManagement config did not specify allowAuctionWithoutConsent. Using system default setting (${DEFAULT_ALLOW_AUCTION_WO_CONSENT}).`);
}

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

if (userCMP === '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.`);
}
}
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
}
config.getConfig('consentManagement', config => setConfig(config.consentManagement));
Loading

0 comments on commit 6a3d628

Please sign in to comment.