Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

fix: update crisp hi message

Dillion Verma1937ee1ac42e
diff --git a/app/layout.tsx b/app/layout.tsx
index e55c0420..e1821c9f 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -11,6 +11,7 @@ import { absoluteUrl, cn, constructMetadata } from "@/lib/utils";
import "@/styles/globals.css";
import "@/styles/mdx.css";
import { Metadata } from "next";
+import { cookies } from "next/headers";
export const metadata: Metadata = constructMetadata({
title: "Magic UI",
@@ -24,6 +25,10 @@ export default function RootLayout({
}: {
children: React.ReactNode;
}) {
+ const cookieStore = cookies();
+ const isNewVisitor =
+ cookieStore.get("__Host-next-auth.csrf-token") === undefined;
+
return (
<html lang="en" suppressHydrationWarning>
<head />
@@ -39,7 +44,7 @@ export default function RootLayout({
<TooltipProvider>
{children}
<PosthogIdentify />
- <CrispChat />
+ <CrispChat isNewVisitor={isNewVisitor} />
<Toaster />
<Analytics />
{/* <TailwindIndicator /> */}
diff --git a/components/crisp-chat.tsx b/components/crisp-chat.tsx
index 4b064300..d3c3b938 100644
--- a/components/crisp-chat.tsx
+++ b/components/crisp-chat.tsx
@@ -4,7 +4,7 @@ import { Crisp } from "crisp-sdk-web";
import { useSession } from "next-auth/react";
import { useEffect } from "react";
-export function CrispChat() {
+export function CrispChat({ isNewVisitor }: { isNewVisitor: boolean }) {
const { data: session } = useSession();
useEffect(() => {
@@ -22,6 +22,17 @@ export function CrispChat() {
Crisp.user.setEmail(session.user.email);
Crisp.user.setNickname(session.user.name || session.user.email);
}
+
+ if (isNewVisitor) {
+ const timeoutId1 = setTimeout(() => {
+ Crisp.message.show("text", "hi there!");
+ }, 1000);
+
+ // Cleanup function to clear timeouts
+ return () => {
+ clearTimeout(timeoutId1);
+ };
+ }
}, [session]);
return null;