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

added cookies consent banner #1634

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"quill-html-edit-button": "^2.2.12",
"react": "18.2.0",
"react-chartjs-2": "^5.2.0",
"react-cookie-consent": "^9.0.0",
"react-dom": "18.2.0",
"react-gtm-module": "2.0.11",
"react-i18next": "^13.2.2",
Expand Down
5 changes: 4 additions & 1 deletion public/locales/bg/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,8 @@
"read-more": "Прочетете още",
"see-profile": "Вижте профил",
"question": "Имате въпрос?"
}
},
"cookieConsent": "Подкрепи.бг не използва бисквитки, освен тези от трети страни, нужни за аналитичните компоненти Google Analytics и HotJar. Приемането на бисквитките ще ни помогне да подобрим вашето потребителско преживяване",
"cookieConsentButton": "Приемам",
"cookieRejectButton": "Отхвърлям"
}
5 changes: 4 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,8 @@
"read-more": "Read more",
"see-profile": "See profile",
"question": "Have a question?"
}
},
"cookieConsent": "Podkrepi.bg doesn't use cookies, except the third-party cookies required for the analytics components Google Analytics and HotJar. Accepting the cookies will help us improve your user experience.",
"cookieConsentButton": "Accept",
"cookieRejectButton": "Reject"
}
45 changes: 45 additions & 0 deletions src/components/common/CookieConsentPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import CookieConsent from 'react-cookie-consent'
import { useTranslation } from 'react-i18next'

type CookieConsentPopupProps = {
handleAcceptCookie: () => void
handleDeclineCookie: () => void
}

const CookieConsentPopup = ({
handleAcceptCookie,
handleDeclineCookie,
}: CookieConsentPopupProps) => {
const { t } = useTranslation()

return (
<CookieConsent
enableDeclineButton
onAccept={handleAcceptCookie}
onDecline={handleDeclineCookie}
buttonText={t('cookieConsentButton')}
declineButtonText={t('cookieRejectButton')}
style={{ border: '1px solid black', backgroundColor: '#fff' }}
contentStyle={{
fontSize: '1rem',
color: '#000',
padding: '0.5rem',
}}
buttonStyle={{
backgroundColor: 'white',
color: '#32a9fe',
border: '1px solid #32a9fe',
borderRadius: '5px',
}}
declineButtonStyle={{
backgroundColor: 'white',
color: '#32a9fe',
border: '1px solid #32a9fe',
borderRadius: '5px',
}}>
{t('cookieConsent')}
</CookieConsent>
)
}

export default CookieConsentPopup
25 changes: 22 additions & 3 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
globalSnackbarProps,
globalSnackbarContentProps,
} from 'components/client/layout/NotificationSnackBar/props/global'
import { getCookieConsentValue, Cookies } from 'react-cookie-consent'
import CookieConsentPopup from 'components/common/CookieConsentPopup'

// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache()
Expand All @@ -46,11 +48,24 @@ function CustomApp({
const { i18n } = useTranslation()
const { initialize, trackEvent } = useGTM()

useEffect(() => {
// Init GTM
const handleAcceptCookie = () => {
initialize({
events: { user_lang: i18n?.language },
events: { user_lang: i18n.language },
})
}

const handleDeclineCookie = () => {
Cookies.remove('_ga')
Cookies.remove('_gat')
Cookies.remove('_gid')
}

useEffect(() => {
const isConsent = getCookieConsentValue()
// Init GTM
if (isConsent === 'true') {
handleAcceptCookie()
}
}, [])

// Register route change complete event handlers
Expand Down Expand Up @@ -108,6 +123,10 @@ function CustomApp({
</QueryClientProvider>
</SessionProvider>
</ThemeProvider>
<CookieConsentPopup
handleAcceptCookie={handleAcceptCookie}
handleDeclineCookie={handleDeclineCookie}
/>
</CacheProvider>
)
}
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9304,6 +9304,13 @@ __metadata:
languageName: node
linkType: hard

"js-cookie@npm:^2.2.1":
version: 2.2.1
resolution: "js-cookie@npm:2.2.1"
checksum: 9b1fb980a1c5e624fd4b28ea4867bb30c71e04c4484bb3a42766344c533faa684de9498e443425479ec68609e96e27b60614bfe354877c449c631529b6d932f2
languageName: node
linkType: hard

"js-tokens@npm:^3.0.0 || ^4.0.0, js-tokens@npm:^4.0.0":
version: 4.0.0
resolution: "js-tokens@npm:4.0.0"
Expand Down Expand Up @@ -11710,6 +11717,7 @@ __metadata:
quill-html-edit-button: ^2.2.12
react: 18.2.0
react-chartjs-2: ^5.2.0
react-cookie-consent: ^9.0.0
react-dom: 18.2.0
react-gtm-module: 2.0.11
react-i18next: ^13.2.2
Expand Down Expand Up @@ -12152,6 +12160,17 @@ __metadata:
languageName: node
linkType: hard

"react-cookie-consent@npm:^9.0.0":
version: 9.0.0
resolution: "react-cookie-consent@npm:9.0.0"
dependencies:
js-cookie: ^2.2.1
peerDependencies:
react: ">=16"
checksum: 56a50f03e21c7345dc97159222fd93e920290653da52fc7bf405b757e84dac183753950c42ea1db6cf633fabd0eded8216986798935bbdeda44ddb2db4dc83e0
languageName: node
linkType: hard

"react-devtools-inline@npm:4.4.0":
version: 4.4.0
resolution: "react-devtools-inline@npm:4.4.0"
Expand Down
Loading