next/script component in your root layout, so it loads on every page. next/script passes data-* props through to the tag.
Before you start
- A website widget with your app on its Allowed origins list. You need the widget id and public key from its snippet.
Add the widget
Open app/layout.tsx
This is the root layout that wraps every page (
app/layout.jsx works the same way).Add the Script component
app/layout.tsx
YOUR_WIDGET_ID and kl_pk_... with the values from your widget’s snippet.<Script> after <Component {...pageProps} /> in pages/_app.tsx, with both inside a fragment (<>…</>).