-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
website(feature): add cookie banner (#640)
- Loading branch information
Showing
13 changed files
with
200 additions
and
54 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 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
14 changes: 9 additions & 5 deletions
14
website/src/app/[lang]/[region]/(website)/transparency/finances/page.tsx
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { CURRENCY_COOKIE } from '@/app/[lang]/[region]'; | ||
import { defaultCurrency } from '@/i18n'; | ||
import { cookies } from 'next/headers'; | ||
'use client'; | ||
|
||
import { useI18n } from '@/app/context-providers'; | ||
import { redirect } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
const currency = cookies().get(CURRENCY_COOKIE)?.value.toLowerCase() || defaultCurrency; | ||
redirect('./finances/' + currency); | ||
const { currency } = useI18n(); | ||
|
||
useEffect(() => { | ||
redirect('./finances/' + currency?.toLowerCase()); | ||
}, []); | ||
} |
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,30 @@ | ||
import { DefaultLayoutProps } from '@/app/[lang]/[region]/index'; | ||
import { CookieConsentBanner } from '@/components/tracking/cookie-consent-banner'; | ||
import { mainWebsiteLanguages, websiteRegions } from '@/i18n'; | ||
import { Translator } from '@socialincome/shared/src/utils/i18n'; | ||
import { PropsWithChildren } from 'react'; | ||
import { Toaster } from 'react-hot-toast'; | ||
|
||
export const generateStaticParams = () => | ||
websiteRegions.flatMap((region) => mainWebsiteLanguages.map((lang) => ({ lang, region }))); | ||
|
||
export default async function Layout({ children, params }: PropsWithChildren<DefaultLayoutProps>) { | ||
const translator = await Translator.getInstance({ | ||
language: params.lang, | ||
namespaces: ['website-common'], | ||
}); | ||
|
||
return ( | ||
<> | ||
<Toaster /> | ||
{children} | ||
<CookieConsentBanner | ||
translations={{ | ||
text: translator.t('cookie-consent-banner.text'), | ||
buttonAccept: translator.t('cookie-consent-banner.button-accept'), | ||
buttonRefuse: translator.t('cookie-consent-banner.button-refuse'), | ||
}} | ||
/> | ||
</> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { Button, Card, CardContent, Typography } from '@socialincome/ui'; | ||
import { ConsentStatusString } from 'firebase/analytics'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
type CookieConsentBannerClientProps = { | ||
translations: { | ||
text: string; | ||
buttonAccept: string; | ||
buttonRefuse: string; | ||
}; | ||
}; | ||
|
||
export function CookieConsentBanner({ translations }: CookieConsentBannerClientProps) { | ||
const [hideBanner, setHideBanner] = useState(true); | ||
|
||
useEffect(() => { | ||
const cookieConsent = localStorage.getItem('cookie_consent'); | ||
setHideBanner(Boolean(cookieConsent)); | ||
}, [setHideBanner]); | ||
|
||
const setCookieConsent = (mode: ConsentStatusString) => { | ||
localStorage.setItem('cookie_consent', mode); | ||
location.reload(); | ||
}; | ||
if (hideBanner) return null; | ||
|
||
return ( | ||
<Card className="fixed bottom-12 left-4 right-4 mx-auto max-w-6xl shadow-xl"> | ||
<CardContent className="flex flex-col space-y-2 p-4"> | ||
<Typography className="md:col-span-3"> | ||
<Typography as="span" dangerouslySetInnerHTML={{ __html: translations.text }} /> | ||
</Typography> | ||
<div className="flex space-x-2"> | ||
<Button variant="outline" onClick={() => setCookieConsent('granted')}> | ||
{translations.buttonAccept} | ||
</Button> | ||
<Button variant="destructive" onClick={() => setCookieConsent('denied')}> | ||
{translations.buttonRefuse} | ||
</Button> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
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,28 @@ | ||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
export function FacebookTracking() { | ||
useEffect(() => { | ||
if (process.env.NEXT_PUBLIC_FACEBOOK_TRACKING_ID) { | ||
console.debug('Enabling Facebook tracking'); | ||
|
||
const fbeventsScript = ` | ||
!function(f,b,e,v,n,t,s) | ||
{if(f.fbq)return;n=f.fbq=function(){n.callMethod? | ||
n.callMethod.apply(n,arguments):n.queue.push(arguments)}; | ||
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; | ||
n.queue=[];t=b.createElement(e);t.async=!0; | ||
t.src=v;s=b.getElementsByTagName(e)[0]; | ||
s.parentNode.insertBefore(t,s)}(window, document,'script', | ||
'https://connect.facebook.net/en_US/fbevents.js'); | ||
fbq('init', '${process.env.NEXT_PUBLIC_FACEBOOK_TRACKING_ID}'); | ||
fbq('track', 'PageView');`; | ||
const scriptElement = document.createElement('script'); | ||
scriptElement.textContent = fbeventsScript; | ||
document.head.appendChild(scriptElement); | ||
} | ||
}, []); | ||
|
||
return null; | ||
} |
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,22 @@ | ||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
export function LinkedInTracking() { | ||
useEffect(() => { | ||
if (process.env.NEXT_PUBLIC_LINKEDIN_TRACKING_ID) { | ||
console.debug('Enabling LinkedIn tracking'); | ||
// @ts-ignore | ||
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || []; | ||
// @ts-ignore | ||
window._linkedin_data_partner_ids.push(process.env.NEXT_PUBLIC_LINKEDIN_TRACKING_ID); | ||
const scriptElement = document.createElement('script'); | ||
scriptElement.type = 'text/javascript'; | ||
scriptElement.async = true; | ||
scriptElement.src = 'https://snap.licdn.com/li.lms-analytics/insight.min.js'; | ||
document.head.appendChild(scriptElement); | ||
} | ||
}, []); | ||
|
||
return null; | ||
} |