Install guides / Vue and Nuxt
Add a support chat widget to Vue and Nuxt
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 Vue and Nuxt.
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 Vue and Nuxt
With Vue and Vite, paste your line into index.html at the project's root, just before </body>:
index.html
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<script src="https://product.tech/widget.js" data-product="acme-invoices" async></script>
</body>With Nuxt, add it to every page from nuxt.config.ts:
nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{
src: "https://product.tech/widget.js",
"data-product": "acme-invoices",
async: true,
tagPosition: "bodyClose",
},
],
},
},
});Good to know
- The widget adds its button to the page's body, outside your app, so Vue Router and Nuxt's page changes keep 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 the dev server, 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 on your server and send the result along with the user your app already loads:
HTML
// On your server, in the route your app already asks for the signed-in user:
import { createHmac } from "node:crypto";
export function productTechUser(user) {
if (!user) return null;
const hash = createHmac("sha256", process.env.PRODUCTTECH_WIDGET_KEY)
.update(user.email.toLowerCase())
.digest("hex");
return { email: user.email, name: user.name ?? "", hash };
}Then hand it to the chat from a watch on your signed-in user, or a Nuxt client plugin:
HTML
// In your app, whenever the signed-in user changes (null when nobody is):
export function tellChat(productTechUser) {
window.ProductTechUser = productTechUser; // read when the widget loads
window.ProductTechWidget?.identify(productTechUser); // tells a widget that is already on the page
}Call tellChat(null) when they sign out. 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.