Skip to content

Consent module doublecall #3399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -56,11 +57,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 @@ -82,7 +83,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 @@ -97,7 +98,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 @@ -139,13 +140,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 @@ -371,6 +374,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));