🐛 (landing-page) Fix first-time cookie setter for non EU users

This commit is contained in:
Baptiste Arnaud 2025-08-20 10:40:35 +02:00
parent 9a9a7e684c
commit 8548d36cda
No known key found for this signature in database
3 changed files with 15 additions and 8 deletions

View File

@ -0,0 +1,7 @@
import { serializeTypebotCookie } from "@typebot.io/telemetry/cookies/helpers";
export const setCookie = (consent: "declined" | "accepted") => {
document.cookie = serializeTypebotCookie({
consent,
});
};

View File

@ -1,4 +1,5 @@
import { isEU } from "@/features/telemetry/server/isEU";
import { setCookie } from "@/helpers/setCookie";
import { getTypebotCookie } from "@typebot.io/telemetry/cookies/helpers";
import { useEffect, useState } from "react";
@ -17,7 +18,12 @@ export const useCookieConsentStatus = () => {
}
isEU().then((response) => {
setCookieConsentStatus(response.isEU ? "need-consent" : "not-needed");
if (response.isEU) {
setCookieConsentStatus("need-consent");
} else {
setCookie("accepted");
setCookieConsentStatus("not-needed");
}
});
}, []);

View File

@ -3,6 +3,7 @@ import { CookieConsentBot } from "@/components/CookieConsentBot";
import { Header } from "@/components/Header";
import { NotFound } from "@/components/NotFound";
import { Footer } from "@/components/footer/Footer";
import { setCookie } from "@/helpers/setCookie";
import { useCookieConsentStatus } from "@/hooks/useIsCookieConsentNeeded";
import { useTrackPageViewQuery } from "@/hooks/useTrackPageViewQuery";
import {
@ -12,7 +13,6 @@ import {
createRootRoute,
useNavigate,
} from "@tanstack/react-router";
import { serializeTypebotCookie } from "@typebot.io/telemetry/cookies/helpers";
import { z } from "@typebot.io/zod";
const HERO_ANIMATION_DELAY = 1800;
@ -102,9 +102,3 @@ function RootComponent() {
</html>
);
}
const setCookie = (consent: "declined" | "accepted") => {
document.cookie = serializeTypebotCookie({
consent,
});
};