diff --git a/.changeset/real-llamas-beam.md b/.changeset/real-llamas-beam.md index dd199b213d..82418633c4 100644 --- a/.changeset/real-llamas-beam.md +++ b/.changeset/real-llamas-beam.md @@ -1,4 +1,4 @@ --- -'@segment/analytics-consent-wrapper-onetrust': patch +'@segment/analytics-consent-wrapper-onetrust': minor --- -Reload on consent change +Full page reload on Consent Change if 'show banner' is unchecked in UI. diff --git a/packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts b/packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts index 01c205ad6c..d0b7498552 100644 --- a/packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts +++ b/packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts @@ -54,21 +54,18 @@ export const withOneTrust = ( : (setCategories) => { const OneTrust = getOneTrustGlobal()! OneTrust.OnConsentChanged((event) => { + const normalizedCategories = getNormalizedCategoriesFromGroupIds( + event.detail + ) + setCategories(normalizedCategories) // if 'show banner' is unchecked in the UI, we assume that there is some implicit consent. // If the user then interacts with the banner want to reload the page to ensure that device mode plugins are reloaded (in case of opt out). - // Gotcha: the consent changed event that is meant to be triggered by the callback above will very likely be skipped, since the page will reload and segment will not have time to capture it. - // Segment does not expose a simple http client that we can use to send 'last chance' events and await a response... or give an API to flush this consent changed event to localStorage before we reload the page. - // The best we could do right now is await some arbitrary timeout and hope that the event is sent or enqueued before the page reloads, but that's unreliable. + // Ideally, we are capturing the consent change event via localStorage right before reload "via the visibilitystate event" if (OneTrust.GetDomainData().ShowAlertNotice === false) { window.location.reload() // skip consent changed event since we're reloading the page return } - - const normalizedCategories = getNormalizedCategoriesFromGroupIds( - event.detail - ) - setCategories(normalizedCategories) }) }, integrationCategoryMappings: settings.integrationCategoryMappings,