Skip to content

Commit

Permalink
set up onetrust cookie management
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshmishri committed Aug 8, 2024
1 parent 56bc1e4 commit fa22895
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
34 changes: 33 additions & 1 deletion scripts/delayed.js
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();
}
});
};
}
8 changes: 8 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,12 @@ main .border-top {
.width-400 {
max-width: 400px;
margin: auto;
}

/* styles to override onetrust */
#onetrust-consent-sdk #onetrust-pc-sdk button:not(#clear-filters-handler):not(.ot-close-icon):not(#filter-btn-handler):not(.ot-remove-objection-handler):not(.ot-obj-leg-btn-handler):not([aria-expanded]):not(.ot-link-btn),
#onetrust-banner-sdk #onetrust-reject-all-handler,
#onetrust-consent-sdk #onetrust-accept-btn-handler {
background-color: var(--link-color) !important;
border-color: transparent !important;
}

0 comments on commit fa22895

Please sign in to comment.