Skip to content

Commit 8443d7d

Browse files
authored
Implement Cookie Consent Management for Microsoft Clarity GDPR Compliance (#770)
1 parent bbadd7a commit 8443d7d

File tree

3 files changed

+530
-8
lines changed

3 files changed

+530
-8
lines changed

EssentialCSharp.Web/Views/Home/Privacy.cshtml

Lines changed: 0 additions & 6 deletions
This file was deleted.

EssentialCSharp.Web/Views/Shared/_Layout.cshtml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,39 @@
7878
<environment exclude="Development">
7979
<script type="importmap" asp-importmap="@prodMap"></script>
8080
</environment>
81+
<!-- Cookie Consent Manager - Load before analytics -->
82+
<script src="~/js/consent-manager.js" asp-append-version="true"></script>
83+
84+
<!-- Microsoft Clarity - Will be activated based on consent -->
8185
<script type="text/javascript">
8286
(function (c, l, a, r, i, t, y) {
8387
c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
8488
t = l.createElement(r); t.async = 1; t.src = "https://www.clarity.ms/tag/" + i;
8589
y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y);
8690
})(window, document, "clarity", "script", "g4keetzd2o");
8791
</script>
92+
8893
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
8994
<!-- Markdown and sanitization libraries -->
9095
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
9196
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.5/dist/purify.min.js"></script>
92-
<!-- Google tag (gtag.js) -->
97+
98+
<!-- Google tag (gtag.js) - Will be activated based on consent -->
9399
<script async src="https://www.googletagmanager.com/gtag/js?id=G-761B4BMK2R"></script>
94100
<script>
95101
window.dataLayer = window.dataLayer || [];
96102
function gtag() { dataLayer.push(arguments); }
103+
104+
// Initialize gtag but don't configure until consent is given
97105
gtag('js', new Date());
98-
gtag('config', 'G-761B4BMK2R');
106+
107+
// Configuration will be handled by consent manager
108+
// Listen for consent manager initialization event
109+
document.addEventListener('consentManagerReady', function(event) {
110+
if (event.detail.hasAnalyticsConsent || !event.detail.requiresConsent) {
111+
gtag('config', 'G-761B4BMK2R');
112+
}
113+
});
99114
</script>
100115
<style>
101116
[v-cloak] {
@@ -506,6 +521,9 @@
506521
<div class="col-12 col-md-auto align-self-end p-2">
507522
<a target="_blank" rel="noreferrer noopener" href="https://intellitect.com/about/privacy-policy/">Privacy</a>
508523
</div>
524+
<div class="col-12 col-md-auto align-self-end p-2">
525+
<a href="javascript:void(0)" onclick="openConsentPreferences()">Cookie Preferences</a>
526+
</div>
509527
<div class="col-12 col-md-auto align-self-end p-2"><a asp-route="TermsOfService">Terms Of Service</a></div>
510528
</div>
511529
</footer>

0 commit comments

Comments
 (0)