If a service is blocked on the initial page load and only gets consent later, it may not initialize properly. In these cases, you can automatically reload the page once consent is granted.
Use the following script to detect that change and refresh the page automatically:
var WATCHED_SERVICES = ['SERVICE NAME', ... ];
var initialConsent = null;
var explicitReceived = false;
window.addEventListener('EVENT NAME', function (e) {
var d = e.detail;
if (d.event !== 'consent_status') return;
if (d.type === 'IMPLICIT' && d.action === 'onInitialPageLoad') {
initialConsent = d;
return;
}
if (d.type !== 'EXPLICIT' || !initialConsent) return;
if (explicitReceived || WATCHED_SERVICES.some(function (s) {
return initialConsent[s] === false && d[s] === true;
})) {
location.reload();
}
explicitReceived = true;
});How it works
This script compares:
- the consent state on the initial page load
- the updated consent state after a user makes an explicit choice
The page reloads when at least one watched service changes from:
falseon initial load- to
trueafter consent is updated
This is useful when a service needs a full page reload before it can initialize properly.
Before you implement
Make sure that:
- you use the exact service names shown in the
dataLayerconsent event - you replace
'EVENT NAME'with the correct custom window event - configure this event in the Implementation section of the Admin Interface
When to use this
Use this only if:
- a service fails to initialize after consent is granted, and
- a simple re-trigger (without reload) is not sufficient
Tip
Only include the services that actually require a reload. This helps avoid unnecessary page refreshes and keeps the user experience smoother.