-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds simpleanalytics and cookie consent
- Loading branch information
1 parent
857d5a0
commit 0957c33
Showing
6 changed files
with
188 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
|
||
const CookieBanner = ({ onClick }) => { | ||
return ( | ||
<div aria-live="assertive" className="cookie-consent"> | ||
<div className="cookie-consent__wrapper"> | ||
<div> | ||
This site uses cookies. <br /> | ||
</div> | ||
<button className="cookie-consent__confirm" onClick={onClick}> | ||
OK | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CookieBanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react"; | ||
import { useCookies } from "react-cookie"; | ||
import CookieBanner from "./CookieBanner"; | ||
|
||
const COOKIES_CONSENT_NAME = "cookie-consent-given"; | ||
const COOKIES_CONSENT_VALUE = 1; | ||
|
||
export default function CookiesConsent() { | ||
const [cookies, setCookie] = useCookies(); | ||
const [consentGiven, setIsConsentGiven] = React.useState( | ||
cookies?.[COOKIES_CONSENT_NAME] === COOKIES_CONSENT_VALUE | ||
); | ||
|
||
return consentGiven ? ( | ||
<> | ||
<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> | ||
</> | ||
) : ( | ||
<CookieBanner | ||
onClick={() => { | ||
const yearFromNow = new Date( | ||
new Date().setFullYear(new Date().getFullYear() + 1) | ||
); | ||
setCookie(COOKIES_CONSENT_NAME, COOKIES_CONSENT_VALUE, { | ||
expires: yearFromNow, | ||
}); | ||
setIsConsentGiven(true); | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import CookiesConsent from "../components/CookieConsent"; | ||
|
||
export default function Root({ children }) { | ||
return ( | ||
<> | ||
{children} | ||
<CookiesConsent /> | ||
</> | ||
); | ||
} |