CanWeChat
← Blog

2026-09-20

Installing the widget in a Next.js app

Drop the CanWeChat script in `app/layout.tsx` (or `_document` on Pages Router) so every route gets the bubble without remounting a client provider tree.

Set allowed domains in Settings so the public site key cannot be reused on a random hostname. After login, call `CanWeChat.identify` with your user id and email so agents see a stable visitor.

Prefer the documented JS API (`open`, `prefill`, `page`, `destroy`) over forking the widget. The dashboard stays on React; the public surface stays a small vanilla IIFE.