Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Nov 10, 2023
1 parent 6f97ff6 commit 387134a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .changeset/real-llamas-beam.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 5 additions & 8 deletions packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@ export const withOneTrust = <Analytics extends AnyAnalytics>(
: (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,
Expand Down

0 comments on commit 387134a

Please sign in to comment.