generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56bc1e4
commit fa22895
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
// add delayed functionality here | ||
import { loadScript } from './aem.js'; | ||
|
||
// OneTrust Cookies Consent Notice | ||
if (!window.location.pathname.includes('srcdoc') | ||
&& !['hlx.live', 'aem.page', 'aem.live'].some((url) => window.location.host.includes(url))) { | ||
// when running on localhost in the block library host is empty but the path is srcdoc | ||
// on localhost/hlx.page/hlx.live the consent notice is displayed every time the page opens, | ||
// because the cookie is not persistent. To avoid this annoyance, disable unless on the | ||
// production page. | ||
loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js', { | ||
type: 'text/javascript', | ||
charset: 'UTF-8', | ||
'data-domain-script': '0190e9aa-e486-72b8-ada6-bda52c32aa2c', | ||
}); | ||
|
||
window.OptanonWrapper = () => { | ||
const currentOnetrustActiveGroups = window.OnetrustActiveGroups; | ||
|
||
function isSameGroups(groups1, groups2) { | ||
const s1 = JSON.stringify(groups1.split(',').sort()); | ||
const s2 = JSON.stringify(groups2.split(',').sort()); | ||
|
||
return s1 === s2; | ||
} | ||
|
||
window.OneTrust.OnConsentChanged(() => { | ||
// reloading the page only when the active group has changed | ||
if (!isSameGroups(currentOnetrustActiveGroups, window.OnetrustActiveGroups)) { | ||
window.location.reload(); | ||
} | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters