Sign up

Next.js

Clearlook in a Next.js app (App Router or Pages Router).

  • App Router: the tag goes in app/layout.tsx, inside <head>, as a plain <script defer …> element or next/script with strategy="afterInteractive". Route changes are recorded by the script; no router hook is needed.
  • Pages Router: the tag goes in pages/_document.tsx inside <Head>.
  • npm: the package isn't on npm yet; use the tag.
  • Keys: NEXT_PUBLIC_PLATFORM_KEY holds the pk_ key. Server-only keys never get the NEXT_PUBLIC_ prefix.
  • Users: in the client component that knows the signed-in user: platform.setConsent('granted'), then platform.identify(user.id).
  • Errors: @sentry/nextjs with the project DSN; source maps upload in CI (errors-sourcemaps).
  • Pitfall: a Content-Security-Policy in next.config or middleware needs https://app.clearlook.dev in script-src and connect-src.