Skip to content

Commit

Permalink
Consent module doublecall (prebid#3399)
Browse files Browse the repository at this point in the history
* * check if consent hook is already set

* * removed debug code

* * formatting
  • Loading branch information
olafbuitelaar authored and Pedro López Jiménez committed Mar 18, 2019
1 parent c54871c commit 41e54c9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export let allowAuction;
export let staticConsentData;

let consentData;
let addedConsentHook = false;

// add new CMPs here, with their dedicated lookup function
const cmpCallMap = {
Expand Down Expand Up @@ -58,11 +59,11 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
}

return {
consentDataCallback: function(consentResponse) {
consentDataCallback: function (consentResponse) {
cmpResponse.getConsentData = consentResponse;
afterEach();
},
vendorConsentsCallback: function(consentResponse) {
vendorConsentsCallback: function (consentResponse) {
cmpResponse.getVendorConsents = consentResponse;
afterEach();
}
Expand All @@ -84,7 +85,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
// if the CMP is not found, the iframe function will call the cmpError exit callback to abort the rest of the CMP workflow
try {
cmpFunction = window.__cmp || utils.getWindowTop().__cmp;
} catch (e) {}
} catch (e) { }

if (utils.isFn(cmpFunction)) {
cmpFunction('getConsentData', null, callbackHandler.consentDataCallback);
Expand All @@ -99,7 +100,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
while (!cmpFrame) {
try {
if (f.frames['__cmpLocator']) cmpFrame = f;
} catch (e) {}
} catch (e) { }
if (f === window.top) break;
f = f.parent;
}
Expand Down Expand Up @@ -141,13 +142,15 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
function callCmpWhileInIframe(commandName, cmpFrame, moduleCallback) {
/* Setup up a __cmp function to do the postMessage and stash the callback.
This function behaves (from the caller's perspective identicially to the in-frame __cmp call */
window.__cmp = function(cmd, arg, callback) {
window.__cmp = function (cmd, arg, callback) {
let callId = Math.random() + '';
let msg = {__cmpCall: {
command: cmd,
parameter: arg,
callId: callId
}};
let msg = {
__cmpCall: {
command: cmd,
parameter: arg,
callId: callId
}
};
cmpCallbacks[callId] = callback;
cmpFrame.postMessage(msg, '*');
}
Expand Down Expand Up @@ -379,6 +382,9 @@ export function setConfig(config) {
utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`);
}
}
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
if (!addedConsentHook) {
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
}
addedConsentHook = true;
}
config.getConfig('consentManagement', config => setConfig(config.consentManagement));

0 comments on commit 41e54c9

Please sign in to comment.