Chat widget
Add the chat to your website, tell it who your users are, and control it from your code.
The widget is one script tag. It adds a chat button in a shadow root, so your page's CSS can't change it, and an iframe served by your Helpdear install.
Add it to a website
Copy the embed code from Settings → Websites and paste it before </body>:
<script>window.Helpdear=window.Helpdear||function(){(Helpdear.q=Helpdear.q||[]).push(arguments)};</script>
<script src="https://help.example.com/widget.js" data-widget="w_your_widget_id" async></script>The first line lets you call Helpdear(...) before the script has loaded; calls wait in a
queue. Attributes on the script tag:
| Attribute | Meaning |
|---|---|
data-widget | Required. The website's widget id. |
data-position="left" | Show the button on the left instead of the right. |
data-hidden="true" | Start hidden; show it later with Helpdear("show"). |
When a website has a domain set, the widget only loads on that domain and its subdomains.
Commands
Helpdear("open"); // open the chat
Helpdear("open", "messages"); // or "help", "feedback", "changelog"
Helpdear("close");
Helpdear("toggle");
Helpdear("show"); // show the button
Helpdear("hide"); // hide the button and close the chat
Helpdear("data", { plan: "Growth", seats: 12 }); // custom data on the contact
Helpdear("on", "message", (event) => {}); // a reply arrived
Helpdear("on", "open", () => {});
Helpdear("on", "close", () => {});
Helpdear("on", "ready", () => {});
Helpdear("reset"); // forget this visitor, for example on sign outCustom data shows on the contact in the inbox. Values are strings, numbers or booleans; null
removes a key. Up to 50 keys.
Identify visitors
Tell the widget who a signed-in user is, so the team sees their name and can email them:
Helpdear("identify", { email: "sam@example.com", name: "Sam Lee", company: "Quill Books" });Without a signature, the email is kept as something the visitor told you. It's shown as unverified and never merges contacts, so typing someone else's email can't reveal their conversations.
Verified identities
To keep a user's history on every device, sign their user id on your server. Create the secret in Settings → Websites → Verified identities, keep it on your server, and send an HMAC-SHA256 of the user id:
// Node.js, on your server
import { createHmac } from "node:crypto";
const hash = createHmac("sha256", process.env.HELPDEAR_IDENTITY_SECRET).update(user.id).digest("hex");// In the page
Helpdear("identify", { userId: user.id, email: user.email, name: user.name, hash });With a valid signature, the visitor joins their existing contact on any browser. If you sign
by email instead (no userId), sign the email. Call Helpdear("reset") when a user signs out,
so the next person on that computer starts fresh.
Pages and single-page apps
The widget reports each page a visitor opens, including route changes in single-page apps, so the inbox shows the pages someone visited before they wrote. A reload of the same page within ten minutes counts once. Page views are kept for 90 days.
Proactive messages
Rules with the "A visitor views a page" trigger show a small message next to the button after a delay, once per visit.