-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cookies banner. Add GA scripts only on user consent (#640)
- Loading branch information
1 parent
6ee03cf
commit fa738aa
Showing
13 changed files
with
232 additions
and
13 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
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
This file was deleted.
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 @@ | ||
export { default } from './component'; |
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,76 @@ | ||
import React from 'react'; | ||
|
||
import { useT } from '@transifex/react'; | ||
|
||
import { AnimatePresence, motion } from 'framer-motion'; | ||
|
||
import Button from 'components/button'; | ||
|
||
import styles from './styles.module.scss'; | ||
|
||
import type { CookiesProps } from './types'; | ||
|
||
function Cookies({ open, onAccept, onReject }: CookiesProps) { | ||
const t = useT(); | ||
return ( | ||
<AnimatePresence> | ||
{open && ( | ||
<div> | ||
<motion.div | ||
initial={{ | ||
opacity: 0, | ||
y: '100%', | ||
}} | ||
animate={{ | ||
opacity: 1, | ||
y: '0%', | ||
transition: { | ||
delay: 0.5, | ||
}, | ||
}} | ||
exit={{ | ||
opacity: 0, | ||
y: '100%', | ||
transition: { | ||
delay: 0, | ||
}, | ||
}} | ||
className={styles.cookies} | ||
> | ||
<div className={styles.bannerContainer}> | ||
<p> | ||
This website uses cookies to ensure you get the best experience | ||
on our website. Read our{' '} | ||
<a | ||
href="https://eowilsonfoundation.org/privacy-policy/" | ||
target="_blank" | ||
rel="noreferrer" | ||
className={styles.link} | ||
> | ||
privacy policy | ||
</a>{' '} | ||
to know more. | ||
</p> | ||
<div className={styles.actions}> | ||
<Button | ||
type="rectangular" | ||
handleClick={onReject} | ||
label={t('Deny')} | ||
className={styles.button} | ||
/> | ||
<Button | ||
type="rectangular-primary" | ||
handleClick={onAccept} | ||
label={t('Accept')} | ||
className={styles.button} | ||
/> | ||
</div> | ||
</div> | ||
</motion.div> | ||
</div> | ||
)} | ||
</AnimatePresence> | ||
); | ||
} | ||
|
||
export default Cookies; |
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,2 @@ | ||
export { default } from './component'; | ||
export type { CookiesProps } from './types'; |
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,49 @@ | ||
@import 'styles/settings'; | ||
@import 'styles/typography-extends'; | ||
|
||
.cookies { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
z-index: $over-modal; | ||
width: 100%; | ||
transform: translateY(100%); | ||
overflow: hidden; | ||
background-color: rgba($navy-he, 0.8); | ||
padding: 6px; | ||
padding-left: 2rem; | ||
outline: none; | ||
|
||
@extend %annotation; | ||
color: $white; | ||
} | ||
|
||
.bannerContainer { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
@media #{$desktop} { | ||
.bannerContainer { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
} | ||
|
||
.link { | ||
color: $white; | ||
font-weight: $font-weight-bold; | ||
text-decoration: underline; | ||
} | ||
|
||
.actions { | ||
display: flex; | ||
justify-content: flex-end; | ||
gap: 1rem; | ||
} | ||
|
||
.button { | ||
min-width: 150px; | ||
} |
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,14 @@ | ||
export interface CookiesProps { | ||
/** | ||
* Whether the modal is opened | ||
*/ | ||
open: boolean; | ||
/** | ||
* Callback executed when the cookies are accepted | ||
*/ | ||
onAccept: () => void; | ||
/** | ||
* Callback executed when the cookies are rejected | ||
*/ | ||
onReject: () => void; | ||
} |
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,57 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import Cookies from 'components/cookies'; | ||
|
||
const { REACT_APP_GA_MEASUREMENT_ID } = process.env; | ||
const consentCookieName = 'HE_COOKIES_CONSENT'; | ||
function ThirdParty() { | ||
const [isOpenCookies, setOpen] = useState(false); | ||
const [scriptAdded, setScriptAdded] = useState(false); | ||
const consentCookie = localStorage.getItem(consentCookieName); | ||
|
||
useEffect(() => { | ||
if (consentCookie === 'true' && !scriptAdded) { | ||
const script1 = document.createElement('script'); | ||
script1.src = `https://www.googletagmanager.com/gtag/js?id=${REACT_APP_GA_MEASUREMENT_ID}`; | ||
script1.async = true; | ||
|
||
const script2 = document.createElement('script'); | ||
script2.innerHTML = ` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${REACT_APP_GA_MEASUREMENT_ID}'); | ||
`; | ||
script2.async = true; | ||
|
||
document.body.appendChild(script1); | ||
document.body.appendChild(script2); | ||
|
||
setScriptAdded(true); | ||
} | ||
}, [consentCookie, scriptAdded]); | ||
|
||
const setConsentCookie = (cookie: string) => | ||
localStorage.setItem(consentCookieName, cookie); | ||
|
||
const handleCookieClick = (c: boolean) => { | ||
setConsentCookie(String(c)); | ||
setOpen(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!consentCookie) { | ||
setOpen(true); | ||
} | ||
}, [consentCookie]); | ||
|
||
return ( | ||
<Cookies | ||
open={isOpenCookies} | ||
onAccept={() => handleCookieClick(true)} | ||
onReject={() => handleCookieClick(false)} | ||
/> | ||
); | ||
} | ||
|
||
export default ThirdParty; |
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 @@ | ||
export { default } from './component'; |
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