Skip to content

Commit 0719cea

Browse files
committed
feat: enhance cookie consent banner for improved readability and functionality
1 parent b1a4498 commit 0719cea

1 file changed

Lines changed: 33 additions & 15 deletions

File tree

src/layouts/Layout.astro

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,34 @@ const socialImageURL = new URL(
8383
</head>
8484
<body>
8585
<slot />
86-
<div id="cookie-banner" style="position:fixed;bottom:0;left:0;width:100%;background:#222;color:#fff;padding:1rem;z-index:1000;display:none;justify-content:center;align-items:center;gap:1rem;font-size:1rem;">
86+
<div
87+
id="cookie-banner"
88+
style="position:fixed;bottom:0;left:0;width:100%;background:#222;color:#fff;padding:1rem;z-index:1000;display:none;justify-content:center;align-items:center;gap:1rem;font-size:1rem;"
89+
>
8790
<span>
88-
This site uses cookies for analytics (Microsoft Clarity). By clicking Accept, you consent to the use of cookies for analytics purposes. See our <a href="/privacy" style="color:#4fd1c5;text-decoration:underline;">privacy policy</a>.
91+
This site uses cookies for analytics (Microsoft Clarity). By clicking
92+
Accept, you consent to the use of cookies for analytics purposes. See
93+
our <a href="/privacy" style="color:#4fd1c5;text-decoration:underline;"
94+
>privacy policy</a
95+
>.
8996
</span>
90-
<button id="cookie-accept" style="background:#4fd1c5;color:#222;padding:0.5rem 1rem;border:none;border-radius:4px;cursor:pointer;">Accept</button>
97+
<button
98+
id="cookie-accept"
99+
style="background:#4fd1c5;color:#222;padding:0.5rem 1rem;border:none;border-radius:4px;cursor:pointer;"
100+
>Accept</button
101+
>
91102
</div>
92103
<script is:inline>
93104
// Show banner if not accepted
94-
if (!window.localStorage.getItem('cookieConsent')) {
95-
document.getElementById('cookie-banner').style.display = 'flex';
105+
if (!window.localStorage.getItem("cookieConsent")) {
106+
document.getElementById("cookie-banner").style.display = "flex";
96107
} else {
97-
window.dispatchEvent(new Event('cookieConsentGiven'));
108+
window.dispatchEvent(new Event("cookieConsentGiven"));
98109
}
99-
document.getElementById('cookie-accept').onclick = function() {
100-
window.localStorage.setItem('cookieConsent', 'true');
101-
document.getElementById('cookie-banner').style.display = 'none';
102-
window.dispatchEvent(new Event('cookieConsentGiven'));
110+
document.getElementById("cookie-accept").onclick = function () {
111+
window.localStorage.setItem("cookieConsent", "true");
112+
document.getElementById("cookie-banner").style.display = "none";
113+
window.dispatchEvent(new Event("cookieConsentGiven"));
103114
};
104115
</script>
105116
<script is:inline>
@@ -117,16 +128,23 @@ const socialImageURL = new URL(
117128
y = l.getElementsByTagName(r)[0];
118129
y.parentNode.insertBefore(t, y);
119130
})(window, document, "clarity", "script", "sb1flusu90");
120-
const clarityUserId = window.localStorage.getItem("userId") || "anonymous";
131+
const clarityUserId =
132+
window.localStorage.getItem("userId") || "anonymous";
121133
const clarityPageId = window.location.pathname;
122134
window.clarityQueue = window.clarityQueue || [];
123-
window.clarity = window.clarity || function() { clarityQueue.push(arguments); };
124-
window.clarity('identify', clarityUserId, undefined, clarityPageId);
135+
window.clarity =
136+
window.clarity ||
137+
function () {
138+
clarityQueue.push(arguments);
139+
};
140+
window.clarity("identify", clarityUserId, undefined, clarityPageId);
125141
}
126-
if (window.localStorage.getItem('cookieConsent')) {
142+
if (window.localStorage.getItem("cookieConsent")) {
127143
loadClarity();
128144
} else {
129-
window.addEventListener('cookieConsentGiven', loadClarity, { once: true });
145+
window.addEventListener("cookieConsentGiven", loadClarity, {
146+
once: true,
147+
});
130148
}
131149
</script>
132150
</body>

0 commit comments

Comments
 (0)