Created
April 27, 2023 19:49
-
-
Save dugjason/bc6562461f6535f435c4f71bef64fba7 to your computer and use it in GitHub Desktop.
Next.JS React component for Front Chat
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
// ./components/front-chat.tsx | |
"use client"; | |
import Script from "next/script"; | |
export function FrontChat() { | |
return ( | |
<Script | |
id="front-chat-script" | |
src="https://chat-assets.frontapp.com/v1/chat.bundle.js" | |
onLoad={initFrontChat} / | |
></Script> | |
); | |
} | |
// Find your chatId in your Front Chat channel settings (in the JS snippet) | |
function initFrontChat() { | |
//@ts-expect-error | |
window.FrontChat("init", { | |
chatId: "YOUR_CHAT_ID", | |
useDefaultLauncher: true, | |
}); | |
} |
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
// ./layout.tsx | |
import "./globals.css"; | |
import { FrontChat } from "@/components/front-chat"; | |
export const metadata = { | |
title: "Create Next App", | |
description: "Generated by create next app", | |
}; | |
export default function RootLayout({ | |
children, | |
}: { | |
children: React.ReactNode; | |
}) { | |
return ( | |
<html lang="en"> | |
<body> | |
{children} | |
{/* The FrontChat component should be inserted before the closing </body> tag, after the main page content */} | |
<FrontChat /> | |
</body> | |
</html> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment