app/ directory), this can be done with just a few lines of code.
Prerequisites
- A Lemon Slice Agent created on a paid plan
- A Next.js project using the App Router
- Basic familiarity with TypeScript and React
Guide
1
Get your embed code
Visit the Lemon Slice agents platform and copy your agent’s embed code. It should look something like this:
2
Add the widget to your layout.tsx
Open your root layout file at Save the file and restart your dev server if needed.
app/layout.tsx.Place the widget inside the <body> so it loads once and persists across pages:3
Register the widget with TypeScript
Since This prevents TypeScript errors during development and builds.
lemon-slice-widget is a custom HTML element, TypeScript needs to be told it’s valid JSX.Create a global declaration file (for example, types/lemon-slice.d.ts) and add:4
Verify the widget is live
Start your app and navigate to any page.
The Lemon Slice agent should load once and remain available as you navigate between routes.
The Lemon Slice agent should load once and remain available as you navigate between routes.
