Install guides / SvelteKit
Add a support chat widget to SvelteKit
The Product.tech chat answers your visitors from your help center, hands the questions it can't answer to your team, and shows what's new. Here's where its line goes on SvelteKit.
Before you start
Copy your own line from your dashboard, on the Chat widget page. The examples here use acme-invoices, our demo product, so swap in yours. The button stays hidden until you publish an article, so it's safe to add the line first.
Add it to SvelteKit
Paste your line into src/app.html, after the app's own element and just before </body>:
src/app.html
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
<script src="https://product.tech/widget.js" data-product="acme-invoices" async></script>
</body>Good to know
- Keep it outside
%sveltekit.body%. The widget adds its button to the page's body, next to your app, so client-side navigation keeps it in place. - To open the chat from your own button, call
window.ProductTechWidget?.open(). - If you list the sites allowed to show your chat, on the Chat widget page, add every address this site is served from, staging addresses included. With no list, any site can show it.
Check that it works
Run npm run dev, open the app and wait a moment: the button appears in the bottom corner.
No button? Open the browser's console. A message starting with [product.tech] says what's wrong, such as a missing data-product or a site that isn't on your list of allowed sites. With nothing there, check that your help center has at least one published article.
Tell the chat who is signed in
When someone is signed in to your product, the chat can show their email address on the conversation in your inbox, so you can write back, and answer them from your private articles. A page can claim to be anyone, so the address comes with a signature your server makes with a key only you hold.
Create a key in your dashboard, under Customer access, then Your site's sign-in. Keep it on your server as PRODUCTTECH_WIDGET_KEY, never in code that reaches the browser.
Sign the user's email address in your root layout's server load:
src/routes/+layout.server.ts
import { createHmac } from "node:crypto";
import { env } from "$env/dynamic/private";
export function load({ locals }) {
const user = locals.user; // however your app keeps the signed-in user
return {
productTechUser: user
? {
email: user.email,
name: user.name ?? "",
hash: createHmac("sha256", env.PRODUCTTECH_WIDGET_KEY).update(user.email.toLowerCase()).digest("hex"),
}
: null,
};
}Then hand it to the chat from the layout, so it follows sign-ins and sign-outs:
src/routes/+layout.svelte
<script>
let { data, children } = $props();
$effect(() => {
window.ProductTechUser = data.productTechUser;
window.ProductTechWidget?.identify(data.productTechUser);
});
</script>
{@render children()}If your app signs in with Firebase, Clerk, Auth0 or Supabase, you can skip the key: name your provider on the same page, and it gives you the one line to add instead.
Options
Add any of these to the line, next to data-product. Each one wins over what you picked on the Chat widget page.
- data-position="left"
- The corner for the button and the chat: left or right.
- data-color="#0a7d5a"
- The button's colour, as a hex value.
- data-label="Need help?"
- The button's words.
- data-theme="dark"
- Light, dark or system, which follows each visitor's device.
To open the chat from a link or button of your own, call ProductTechWidget.open().
Other platforms
New to Product.tech? It writes your help center from your live app, and from your code once you connect GitHub, then drafts release notes from merged pull requests. See how it works.