Skip to content

Commit 41e54c9

Browse files
olafbuitelaarPedro López Jiménez
authored and
Pedro López Jiménez
committed
Consent module doublecall (prebid#3399)
* * check if consent hook is already set * * removed debug code * * formatting
1 parent c54871c commit 41e54c9

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

modules/consentManagement.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export let allowAuction;
2222
export let staticConsentData;
2323

2424
let consentData;
25+
let addedConsentHook = false;
2526

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

6061
return {
61-
consentDataCallback: function(consentResponse) {
62+
consentDataCallback: function (consentResponse) {
6263
cmpResponse.getConsentData = consentResponse;
6364
afterEach();
6465
},
65-
vendorConsentsCallback: function(consentResponse) {
66+
vendorConsentsCallback: function (consentResponse) {
6667
cmpResponse.getVendorConsents = consentResponse;
6768
afterEach();
6869
}
@@ -84,7 +85,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
8485
// if the CMP is not found, the iframe function will call the cmpError exit callback to abort the rest of the CMP workflow
8586
try {
8687
cmpFunction = window.__cmp || utils.getWindowTop().__cmp;
87-
} catch (e) {}
88+
} catch (e) { }
8889

8990
if (utils.isFn(cmpFunction)) {
9091
cmpFunction('getConsentData', null, callbackHandler.consentDataCallback);
@@ -99,7 +100,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
99100
while (!cmpFrame) {
100101
try {
101102
if (f.frames['__cmpLocator']) cmpFrame = f;
102-
} catch (e) {}
103+
} catch (e) { }
103104
if (f === window.top) break;
104105
f = f.parent;
105106
}
@@ -141,13 +142,15 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
141142
function callCmpWhileInIframe(commandName, cmpFrame, moduleCallback) {
142143
/* Setup up a __cmp function to do the postMessage and stash the callback.
143144
This function behaves (from the caller's perspective identicially to the in-frame __cmp call */
144-
window.__cmp = function(cmd, arg, callback) {
145+
window.__cmp = function (cmd, arg, callback) {
145146
let callId = Math.random() + '';
146-
let msg = {__cmpCall: {
147-
command: cmd,
148-
parameter: arg,
149-
callId: callId
150-
}};
147+
let msg = {
148+
__cmpCall: {
149+
command: cmd,
150+
parameter: arg,
151+
callId: callId
152+
}
153+
};
151154
cmpCallbacks[callId] = callback;
152155
cmpFrame.postMessage(msg, '*');
153156
}
@@ -379,6 +382,9 @@ export function setConfig(config) {
379382
utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`);
380383
}
381384
}
382-
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
385+
if (!addedConsentHook) {
386+
$$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50);
387+
}
388+
addedConsentHook = true;
383389
}
384390
config.getConfig('consentManagement', config => setConfig(config.consentManagement));

0 commit comments

Comments
 (0)