diff --git a/package-lock.json b/package-lock.json index 73b2f91c..568bfdd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "docusaurus-plugin-image-zoom": "^2.0.0", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", + "react-cookie-consent": "9.0.0", "react-dom": "^18.0.0" }, "devDependencies": { @@ -10286,6 +10287,12 @@ "@sideway/pinpoint": "^2.0.0" } }, + "node_modules/js-cookie": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz", + "integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==", + "license": "MIT" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -14826,6 +14833,21 @@ "node": ">=0.10.0" } }, + "node_modules/react-cookie-consent": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/react-cookie-consent/-/react-cookie-consent-9.0.0.tgz", + "integrity": "sha512-Blyj+m+Zz7SFHYqT18p16EANgnSg2sIyU6Yp3vk83AnOnSW7qnehPkUe4+8+qxztJrNmCH5GP+VHsWzAKVOoZA==", + "license": "MIT", + "dependencies": { + "js-cookie": "^2.2.1" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "react": ">=16" + } + }, "node_modules/react-dev-utils": { "version": "12.0.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-12.0.1.tgz", diff --git a/package.json b/package.json index bddbd982..1dd3dcc1 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "docusaurus-plugin-image-zoom": "^2.0.0", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", + "react-cookie-consent": "9.0.0", "react-dom": "^18.0.0" }, "devDependencies": { diff --git a/src/theme/Root.js b/src/theme/Root.js new file mode 100644 index 00000000..5666b059 --- /dev/null +++ b/src/theme/Root.js @@ -0,0 +1,58 @@ +import React, { useEffect } from 'react'; +import Clarity from '@microsoft/clarity'; +import CookieConsent from "react-cookie-consent"; + +// Initialize Clarity with the given project ID +const projectId = "p90sis7r0o"; + +export default function Root({ children }) { + useEffect(() => { + if (typeof window !== "undefined") { + // Initialize Clarity only on the client-side + Clarity.init(projectId); + + // Add an event listener for the consent event + window.addEventListener("CookieConsent", () => { + if (window.clarity) { + window.clarity('consent'); + console.log("Clarity consent event triggered."); + } + }); + } + }, []); + + const handleConsentAccept = () => { + // Dispatch a custom "CookieConsent" event when the user accepts cookies + const consentEvent = new Event("CookieConsent"); + window.dispatchEvent(consentEvent); + console.log("CookieConsent event dispatched."); + }; + + return ( + <> + {children} +