Skip to content

Commit

Permalink
chore: change initial flow
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnuescheler committed Jun 27, 2024
1 parent 4cc1faa commit 58d788a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 0 additions & 7 deletions scripts/delayed.js

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/marketing-tech.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// add tag management code here, marketing or advertising functionality
// this file is gated by consent
21 changes: 18 additions & 3 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,31 @@ async function loadLazy(doc) {
* Loads everything that happens a lot later,
* without impacting the user experience.
*/
function loadDelayed() {
async function loadMarketingTech() {
const mapStatus = (consentStatus) => {
if (consentStatus === 'declineAll') return false;
return true;
};
const checkConsent = () => {
const consentStatus = localStorage.getItem('consentStatus');
if (consentStatus !== null) return mapStatus(consentStatus);
return new Promise((resolve) => {
// display consent banner
document.addEventListener('aem:changeconsent', (e) => {
localStorage.setItem('consentStatus', e.detail.consentStatus);
resolve(mapStatus(e.detail.consentStatus));
});
});
};
// eslint-disable-next-line import/no-cycle
window.setTimeout(() => import('./delayed.js'), 3000);
if (await checkConsent()) import('./marketing-tech.js');
// load anything that can be postponed to the latest here
}

async function loadPage() {
await loadEager(document);
await loadLazy(document);
loadDelayed();
loadMarketingTech();
}

loadPage();

0 comments on commit 58d788a

Please sign in to comment.