diff --git a/modules/userId/index.js b/modules/userId/index.js index a53de7aefb0..199934f4cdb 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -592,9 +592,6 @@ function refreshUserIds(options, callback) { initializeSubmodulesAndExecuteCallbacks(function() { let consentData = gdprDataHandler.getConsentData() - const storedConsentData = getStoredConsentData(); - setStoredConsentData(consentData); - // gdpr consent with purpose one is required, otherwise exit immediately let {userIdModules, hasValidated} = validateGdprEnforcement(submodules, consentData); if (!hasValidated && !hasGDPRConsent(consentData)) { @@ -602,6 +599,10 @@ function refreshUserIds(options, callback) { return; } + // we always want the latest consentData stored, even if we don't execute any submodules + const storedConsentData = getStoredConsentData(); + setStoredConsentData(consentData); + let callbackSubmodules = []; for (let submodule of userIdModules) { if (submoduleNames.length > 0 && @@ -691,10 +692,6 @@ function populateSubmoduleId(submodule, consentData, storedConsentData, forceRef * @returns {SubmoduleContainer[]} initialized submodules */ function initSubmodules(submodules, consentData) { - // we always want the latest consentData stored, even if we don't execute any submodules - const storedConsentData = getStoredConsentData(); - setStoredConsentData(consentData); - // gdpr consent with purpose one is required, otherwise exit immediately let { userIdModules, hasValidated } = validateGdprEnforcement(submodules, consentData); if (!hasValidated && !hasGDPRConsent(consentData)) { @@ -702,6 +699,10 @@ function initSubmodules(submodules, consentData) { return []; } + // we always want the latest consentData stored, even if we don't execute any submodules + const storedConsentData = getStoredConsentData(); + setStoredConsentData(consentData); + return userIdModules.reduce((carry, submodule) => { populateSubmoduleId(submodule, consentData, storedConsentData, false); carry.push(submodule);