Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: simple analytics #98

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/components/CookieConsent/index.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import React from "react";
import { useCookies } from "react-cookie";
import CookieBanner from "./CookieBanner";
import Head from '@docusaurus/Head';
import useIsBrowser from '@docusaurus/useIsBrowser';

const COOKIES_CONSENT_NAME = "cookie-consent-given";
const COOKIES_CONSENT_VALUE = 1;

export default function CookiesConsent() {
if (typeof window === "undefined") return null;
const isBrowser = useIsBrowser();
if(!isBrowser) return null
const [cookies, setCookie] = useCookies();
const [consentGiven, setIsConsentGiven] = React.useState(
cookies?.[COOKIES_CONSENT_NAME] === COOKIES_CONSENT_VALUE
);

return consentGiven ? (
<>
<Head>
<script
async
defer
src="https://scripts.simpleanalyticscdn.com/latest.js"
></script>
<noscript>
<img
src="https://queue.simpleanalyticscdn.com/noscript.gif"
alt=""
referrerPolicy="no-referrer-when-downgrade"
/>
</noscript>
</>
<noscript>{`<img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" referrerPolicy="no-referrer-when-downgrade" />`}</noscript>
</Head>
) : (
<CookieBanner
onClick={() => {
Expand Down
Loading