Skip to content

Commit 4b5a1a8

Browse files
committed
Removed CookieYes loader, which was moved into GTM
1 parent 35bf180 commit 4b5a1a8

File tree

2 files changed

+1
-93
lines changed

2 files changed

+1
-93
lines changed

src/app/models/accounts-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default {
9090
// ]
9191
// });
9292

93-
// This code is shared with the CookieYes loader in index.html
93+
// This code is shared with the CookieYes loader in GTM
9494
window._OX_USER_PROMISE ||= fetch(accountsUrl, {credentials: 'include'}).then(
9595
(response) => response.json()
9696
);

src/index.html

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -24,98 +24,6 @@
2424
<link rel="preconnect" href="https://connect.facebook.net" crossorigin="anonymous">
2525
<link rel="prefetch" href="<%= process.env.API_ORIGIN %>/apps/cms/api/books/?format=json">
2626
<link rel="prefetch" href="<%= process.env.API_ORIGIN %>/apps/cms/api/footer/?format=json">
27-
<script>
28-
// This code is shared with the accounts-model
29-
window._OX_USER_PROMISE ||= fetch('/accounts/api/user?always_200=true', {credentials: 'include'}).then(
30-
(response) => response.json()
31-
);
32-
33-
// This method is called when the CookieYes banner loads and we don't have a recorded consent at all,
34-
// from neither Accounts nor the CookieYes cookie
35-
const closeButtonRejectsAll = () => {
36-
// Interpret clicking the X button on the banner as rejecting all cookies
37-
document.getElementsByClassName('cky-banner-btn-close')[0]?.addEventListener(
38-
'click', () => performBannerAction('reject')
39-
);
40-
};
41-
42-
// The user is logged out or user load failed, so we just do the closeButtonRejectsAll() part for consistency
43-
// and don't try to record the consent in Accounts
44-
const addCookieYesListenersForNoUser = () => {
45-
document.addEventListener('cookieyes_banner_load', (eventData) => {
46-
if (!eventData.detail.isUserActionCompleted) {
47-
closeButtonRejectsAll();
48-
}
49-
});
50-
};
51-
52-
window._OX_USER_PROMISE.then((user) => {
53-
if (!user.id) { return addCookieYesListenersForNoUser(); }
54-
55-
const updateUserConsentPreferences = (consentPreferences) => {
56-
return fetch('/accounts/api/user', {
57-
body: JSON.stringify({consent_preferences: consentPreferences}),
58-
credentials: 'include',
59-
headers: { 'Content-Type': 'application/json' },
60-
method: 'PUT',
61-
}).then(
62-
(response) => {
63-
if (response.ok) {
64-
window.location.reload();
65-
} else {
66-
throw new Error(`Failed to save cookie consent: HTTP ${response.status} status code`);
67-
}
68-
}
69-
);
70-
};
71-
72-
document.addEventListener('cookieyes_banner_load', async(eventData) => {
73-
const userConsentPreferences = user?.consent_preferences;
74-
75-
if (userConsentPreferences) {
76-
// Accounts remembers some state
77-
// We always defer to Accounts in this case
78-
79-
// Only call the CookieYes API if it doesn't match what's in Accounts
80-
let doUpdate = !eventData.detail.isUserActionCompleted;
81-
82-
userConsentPreferences.accepted.forEach((accepted) => {
83-
// There is no "necessary" switch
84-
if (accepted !== 'necessary') {
85-
document.getElementById(`ckySwitch${accepted}`).checked = true;
86-
if (!eventData.detail.categories[accepted]) { doUpdate = true; }
87-
}
88-
});
89-
userConsentPreferences.rejected.forEach((rejected) => {
90-
document.getElementById(`ckySwitch${rejected}`).checked = false;
91-
if (eventData.detail.categories[rejected]) { doUpdate = true; }
92-
});
93-
if (doUpdate) { performBannerAction('accept_partial'); }
94-
} else if (eventData.detail.isUserActionCompleted) {
95-
// Accounts doesn't have state but somehow CookieYes does
96-
// This can happen because of 3rd party cookies enabled, non-embedded launch, etc
97-
// Ideally we'd clear the CookieYes consent and let users click the banner again,
98-
// but there's no API to do that
99-
// So instead we make a request to save the user consent to Accounts
100-
const bannerConsentPreferences = { accepted: [], rejected: [] };
101-
Object.entries(eventData.detail.categories).forEach(([category, accepted]) => {
102-
const arr = accepted ? bannerConsentPreferences.accepted : bannerConsentPreferences.rejected;
103-
arr.push(category);
104-
});
105-
return updateUserConsentPreferences(bannerConsentPreferences);
106-
} else {
107-
closeButtonRejectsAll();
108-
}
109-
});
110-
111-
document.addEventListener(
112-
'cookieyes_consent_update', (eventData) => updateUserConsentPreferences(eventData.detail)
113-
);
114-
}, () => addCookieYesListenersForNoUser());
115-
</script>
116-
<!-- Start cookieyes banner -->
117-
<script id="cookieyes" type="text/javascript" src="https://cdn-cookieyes.com/client_data/7c03144a7ef8b7f646f1ce01/script.js"></script>
118-
<!-- End cookieyes banner -->
11927
<script src="//script.crazyegg.com/pages/scripts/0084/9271.js" async="async"></script>
12028
</head>
12129
<body class="page-loading">

0 commit comments

Comments
 (0)