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

Cookie Banner homepage #2400

Merged
merged 3 commits into from
Nov 6, 2023
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
92 changes: 83 additions & 9 deletions front/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {

const defaultFlexClasses = "flex flex-col gap-4";

import { Transition } from "@headlessui/react";

import {
SignInDropDownButton,
SignUpDropDownButton,
Expand Down Expand Up @@ -90,6 +92,9 @@ export default function Home({
const scrollRef3 = useRef<HTMLDivElement | null>(null);
const scrollRef4 = useRef<HTMLDivElement | null>(null);

const [showCookieBanner, setShowCookieBanner] = useState<boolean>(true);
const [hasAcceptedCookies, setHasAcceptedCookies] = useState<boolean>(false);

useEffect(() => {
if (logoRef.current) {
const logoPosition = logoRef.current.offsetTop;
Expand Down Expand Up @@ -752,21 +757,34 @@ export default function Home({
</div>

<Footer />
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${gaTrackingId}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
<CookieBanner
className="fixed bottom-4 right-4"
show={showCookieBanner}
onClickAccept={() => {
setHasAcceptedCookies(true);
setShowCookieBanner(false);
}}
onClickRefuse={() => {
setShowCookieBanner(false);
}}
/>
{hasAcceptedCookies && (
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${gaTrackingId}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${gaTrackingId}');
`}
</Script>
</>
</Script>
</>
)}
</main>
</>
);
Expand Down Expand Up @@ -969,3 +987,59 @@ const Footer = () => {
</div>
);
};

const CookieBanner = ({
show,
onClickAccept,
onClickRefuse,
className,
}: {
show: boolean;
onClickAccept: () => void;
onClickRefuse: () => void;
className?: string;
}) => {
return (
<Transition
show={show}
enter="transition-opacity s-duration-300"
appear={true}
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-opacity duration-300"
leaveFrom="opacity-100"
leaveTo="opacity-0"
className={classNames(
"z-30 flex w-64 flex-col gap-3 rounded-xl border border-structure-100 bg-white p-4 shadow-xl",
className || ""
)}
>
<div className="text-sm font-normal text-element-900">
We use{" "}
<A variant="primary">
<Link
href="https://dust-tt.notion.site/Cookie-Policy-ec63a7fb72104a7babff1bf413e2c1ec"
target="_blank"
>
cookies
</Link>
</A>{" "}
to improve your experience on our site.
</div>
<div className="flex gap-2">
<Button
variant="tertiary"
size="sm"
label="Reject"
onClick={onClickRefuse}
/>
<Button
variant="primary"
size="sm"
label="Accept All"
onClick={onClickAccept}
/>
</div>
</Transition>
);
};