Skip to content

Reload page after customer gives or changes consents

The following script refreshes the page when a user gives or changes their consent.

Replace ucEvent with the name you defined in the respective configuration under Implementation - Data Layer and Events - Window Event - Window Event Name.

This script sets a variable to differentiate between the page load and the consent change.

<script>
  var page = 0;
  window.addEventListener('ucEvent', function (e) {
    if (e.detail.event == 'consent_status' && e.detail.type == 'IMPLICIT' && page == 0) {
      page = 0;
    } else {
      if (e.detail.event == 'consent_status' && e.detail.type == 'EXPLICIT' && page == 0) {
        page = 1;
      } else {
        if (e.detail.event == 'consent_status' && e.detail.type == 'EXPLICIT' && page == 1) {
          location.reload();
        }
      }
    }
  });
</script>