Chat on your own website
Add Puddle Chat to a website Puddle doesn't host, and recognise your signed-in users.
Puddle Chat works on any website: a custom storefront built with the Puddle SDK, a site on another platform, or plain HTML. You paste one script tag, and conversations land in your Inbox.
Before you start
You need a custom storefront for the website in the admin (Websites → Custom storefront):
- A storefront key. Under Create a storefront key, create one. This publishable key is safe to put in your website's HTML.
- Your website's domain. Under Connect your domains, your site's address must be listed. Chat only answers pages on these domains, so a copied key doesn't work on someone else's site. Puddle support connects domains for you.
Then turn chat on: in Settings → Inbox, under Live chat, click Add live chat next to the website.
Install
Paste this before </body> on every page, with your storefront key:
<script async src="https://api.puddle.co.za/inbox/v1/loader.js" data-key="YOUR_PUBLISHABLE_KEY"></script>The script is a few KB. It shows the chat bubble only when chat is on for the website, and loads the rest of the chat the first time someone opens it. Everything is drawn in a Shadow DOM, so your site's CSS can't break it and it can't break your site's.
Each visitor gets a random token kept in their browser's local storage, so a returning visitor sees their conversation again. Nothing is stored for a visitor until they send a message.
Control it from your page
The script adds window.Puddle.chat:
| Call | What it does |
|---|---|
Puddle.chat.open() | Opens the chat panel |
Puddle.chat.close() | Closes it |
Puddle.chat.toggle() | Opens or closes it |
Puddle.chat.setContext({ productId, orderId }) | Tells the chat what the visitor is looking at. A product is linked to the conversation; an order is linked only if it belongs to the verified visitor |
Puddle.chat.identify({ userId, email, name, hash }) | Says who the visitor is. See below |
Puddle.chat.on(event, listener) | Listens for ready (chat is on and loaded), open, close and message (a new message while the panel is loaded) |
For example, a "Chat with us" button:
<button onclick="Puddle.chat.open()">Chat with us</button>The script loads asynchronously, so window.Puddle may not exist yet when your code runs. To call it straight away, add this stub before the script tag. The chat replays the calls once it loads:
<script>
window.Puddle = window.Puddle || {};
window.Puddle.chat = window.Puddle.chat || (function () {
var q = [];
function stub(name) { return function () { q.push([name, [].slice.call(arguments)]); }; }
return { q: q, open: stub("open"), close: stub("close"), toggle: stub("toggle"),
identify: stub("identify"), setContext: stub("setContext"), on: stub("on") };
})();
</script>Recognise signed-in users
If your website has its own accounts, you can tell the chat who the visitor is. Their conversations then follow them across devices, and you see the same person in the Inbox every time.
The chat only trusts this when your server signs it, so nobody can pretend to be one of your users:
- In Settings → Inbox, under your website's live chat, click Reveal next to Identity secret. Keep it on your server, like a password. Rotate makes a new one and stops the old one working.
- On your server, sign the signed-in user's id: the hex HMAC-SHA256 of the user id, keyed with the identity secret.
- In the page, pass the user id and the signature to
identify.
With the Puddle SDK (@puddle/storefront), use signChatIdentity. It runs in Node 18+, Deno, Bun and edge runtimes:
import { signChatIdentity } from "@puddle/storefront";
// On your server, for the signed-in user:
const hash = await signChatIdentity(process.env.PUDDLE_CHAT_SECRET!, user.id);Without the SDK, in Node:
import { createHmac } from "node:crypto";
const hash = createHmac("sha256", process.env.PUDDLE_CHAT_SECRET!).update(user.id).digest("hex");Then in the page:
Puddle.chat.identify({ userId: "user_123", email: "[email protected]", name: "Thandi", hash: "<hash from your server>" });A visitor with a missing or wrong signature chats anonymously; the chat never fails because of it. If they chatted anonymously before signing in, what they wrote moves to their account. email and name are shown in the Inbox to help you, but only the signed user id identifies them.
React and Next.js
Load the script once and keep the visitor and page in step with effects. A small client component:
"use client";
import { useEffect } from "react";
type Identity = { userId: string; email?: string; name?: string; hash: string };
export function PuddleChat({ publishableKey, identity, productId }: {
publishableKey: string;
identity?: Identity | null;
productId?: string;
}) {
useEffect(() => {
if (document.querySelector("script[data-puddle-chat]")) return;
const q: [string, unknown[]][] = [];
const stub = (name: string) => (...args: unknown[]) => { q.push([name, args]); };
(window as any).Puddle = { chat: { q, open: stub("open"), identify: stub("identify"), setContext: stub("setContext") } };
const script = document.createElement("script");
script.src = "https://api.puddle.co.za/inbox/v1/loader.js";
script.async = true;
script.dataset.key = publishableKey;
script.dataset.puddleChat = "";
document.body.append(script);
}, [publishableKey]);
useEffect(() => {
if (identity) (window as any).Puddle?.chat?.identify(identity);
}, [identity]);
useEffect(() => {
if (productId) (window as any).Puddle?.chat?.setContext({ productId });
}, [productId]);
return null;
}Render it once in your root layout, with identity signed by your server for the signed-in user.
Troubleshooting
| Problem | What to do |
|---|---|
| No chat bubble | Check chat is on for this website in Settings → Inbox (not paused), the key is this website's storefront key, and the page's domain is listed under Connect your domains. The browser console shows the request to /inbox/v1/session and its error |
| The bubble shows, but messages fail | The visitor may be sending too fast (20 messages a minute), or the message is over 2,000 characters |
| Signed-in users show as "Website visitor, not verified" | The signature doesn't match: sign exactly the userId you pass to identify, with the current identity secret (after Rotate, update your server) |

