Documentation Index

Fetch the complete documentation index at: https://usercentrics.document360.io/llms.txt

Use this file to discover all available pages before exploring further.

Reload page after customer gives or changes consents

Prev Next

The following script refreshes the page when a user gives or changes their consent. This script uses the page variable to differentiate between the page load and the consent change.

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

<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>