Skip to content

Commit 58d788a

Browse files
chore: change initial flow
1 parent 4cc1faa commit 58d788a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

scripts/delayed.js

-7
This file was deleted.

scripts/marketing-tech.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// add tag management code here, marketing or advertising functionality
2+
// this file is gated by consent

scripts/scripts.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,31 @@ async function loadLazy(doc) {
120120
* Loads everything that happens a lot later,
121121
* without impacting the user experience.
122122
*/
123-
function loadDelayed() {
123+
async function loadMarketingTech() {
124+
const mapStatus = (consentStatus) => {
125+
if (consentStatus === 'declineAll') return false;
126+
return true;
127+
};
128+
const checkConsent = () => {
129+
const consentStatus = localStorage.getItem('consentStatus');
130+
if (consentStatus !== null) return mapStatus(consentStatus);
131+
return new Promise((resolve) => {
132+
// display consent banner
133+
document.addEventListener('aem:changeconsent', (e) => {
134+
localStorage.setItem('consentStatus', e.detail.consentStatus);
135+
resolve(mapStatus(e.detail.consentStatus));
136+
});
137+
});
138+
};
124139
// eslint-disable-next-line import/no-cycle
125-
window.setTimeout(() => import('./delayed.js'), 3000);
140+
if (await checkConsent()) import('./marketing-tech.js');
126141
// load anything that can be postponed to the latest here
127142
}
128143

129144
async function loadPage() {
130145
await loadEager(document);
131146
await loadLazy(document);
132-
loadDelayed();
147+
loadMarketingTech();
133148
}
134149

135150
loadPage();

0 commit comments

Comments
 (0)