threadhive-widget
v1.0.0
Published
Official loader for the ThreadHive chat widget — drop AI-powered support chat into any web app (React, Next.js, Vue, plain JS).
Downloads
173
Maintainers
Readme
threadhive-widget
Official loader for the ThreadHive chat widget — AI-powered support chat for any web app.
npm install threadhive-widgetQuick start
import { init } from "threadhive-widget";
init({ widgetKey: "wk_your_key" }); // Dashboard → Chatbot → InstallThat's it — the launcher appears bottom-right, AI answers from your help center, and hands off to your team when unsure.
React / Next.js
"use client";
import { useEffect } from "react";
import { init } from "threadhive-widget";
export function ThreadHiveProvider() {
useEffect(() => {
init({ widgetKey: process.env.NEXT_PUBLIC_THREADHIVE_KEY! });
}, []);
return null;
}SSR-safe: every call is a no-op on the server.
Identify signed-in users
import { identify, reset } from "threadhive-widget";
// After login. Compute userHash server-side:
// HMAC_SHA256(userId, your_identity_secret)
identify({ userId: "u_123", email: "[email protected]", name: "Ada" }, userHash);
// On logout:
reset();Track events
import { track, page, getVisitorId } from "threadhive-widget";
track("plan_upgraded", { plan: "pro" });
page(); // manual pageview (SPA route changes are auto-tracked)
getVisitorId(); // anonymous visitor id, once loadedSelf-hosted ThreadHive
init({ widgetKey: "wk_…", origin: "https://your-domain.com/api" });API
| Function | Description |
| --- | --- |
| init(options) | Load the widget. Idempotent; returns a promise. |
| identify(traits, userHash?) | Link the visitor to a user. userId required. |
| track(name, props?) | Record a custom event. |
| page(props?) | Record a pageview. |
| reset() | Forget the visitor (logout). |
| getVisitorId() | Anonymous visitor id. |
Calls made before init() resolves are queued and flushed automatically.
License
MIT © ThreadHive — [email protected]
