|
| 1 | +--- |
| 2 | +const projectId = import.meta.env.VITE_CLARITY_PROJECT_ID |
| 3 | +--- |
| 4 | + |
| 5 | +<div |
| 6 | + id="cookie-banner" |
| 7 | + data-clarity-id={projectId} |
| 8 | + class="hidden fixed bottom-0 left-0 right-0 z-50 p-4 bg-editor-bg border-t border-stroke-color shadow-lg" |
| 9 | +> |
| 10 | + <div class="max-w-4xl mx-auto flex flex-col sm:flex-row items-center justify-between gap-4"> |
| 11 | + <p class="text-sm text-secondary/80"> |
| 12 | + Usamos cookies de analítica para mejorar tu experiencia. ¿Aceptas? |
| 13 | + </p> |
| 14 | + <div class="flex gap-3 shrink-0"> |
| 15 | + <button |
| 16 | + id="reject-cookies" |
| 17 | + class="px-4 py-2 text-sm text-secondary/70 border border-stroke-color rounded hover:bg-stroke-color/30 transition-colors cursor-pointer" |
| 18 | + > |
| 19 | + Rechazar |
| 20 | + </button> |
| 21 | + <button |
| 22 | + id="accept-cookies" |
| 23 | + class="px-4 py-2 text-sm bg-yellow text-primary font-semibold rounded hover:opacity-90 transition-opacity cursor-pointer" |
| 24 | + > |
| 25 | + Aceptar |
| 26 | + </button> |
| 27 | + </div> |
| 28 | + </div> |
| 29 | +</div> |
| 30 | + |
| 31 | +<script> |
| 32 | + import Clarity from "@microsoft/clarity" |
| 33 | + |
| 34 | + const banner = document.getElementById("cookie-banner") |
| 35 | + const projectId = banner?.dataset.clarityId ?? "" |
| 36 | + |
| 37 | + function loadClarity() { |
| 38 | + if (projectId) { |
| 39 | + Clarity.init(projectId) |
| 40 | + Clarity.consentV2({ ad_Storage: "granted", analytics_Storage: "granted" }) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + const consent = localStorage.getItem("cookiesAccepted") |
| 45 | + |
| 46 | + if (consent === "true") { |
| 47 | + loadClarity() |
| 48 | + } else if (consent === null) { |
| 49 | + banner?.classList.remove("hidden") |
| 50 | + } |
| 51 | + |
| 52 | + document.getElementById("accept-cookies")?.addEventListener("click", () => { |
| 53 | + localStorage.setItem("cookiesAccepted", "true") |
| 54 | + loadClarity() |
| 55 | + banner?.classList.add("hidden") |
| 56 | + }) |
| 57 | + |
| 58 | + document.getElementById("reject-cookies")?.addEventListener("click", () => { |
| 59 | + localStorage.setItem("cookiesAccepted", "false") |
| 60 | + banner?.classList.add("hidden") |
| 61 | + }) |
| 62 | +</script> |
0 commit comments