Add the script in your app.vue:
<template>
<div>
<NuxtPage />
</div>
</template>
<script setup>
useHead({
script: [
{
src: 'https://js.tokwork.com/loader.js',
async: true,
'data-website-id': 'YOUR_WEBSITE_ID',
'data-website-domain': 'yourdomain.com',
}
]
})
</script>
Configure globally in nuxt.config.ts:
export default defineNuxtConfig({
app: {
head: {
script: [
{
src: 'https://js.tokwork.com/loader.js',
async: true,
'data-website-id': 'YOUR_WEBSITE_ID',
'data-website-domain': 'yourdomain.com',
}
]
}
}
})
For different environments:
export default defineNuxtConfig({
app: {
head: {
script: process.env.NODE_ENV === 'production'
? [
{
src: 'https://js.tokwork.com/loader.js',
async: true,
'data-website-id': process.env.TOKWORK_WEBSITE_ID,
'data-website-domain': process.env.TOKWORK_DOMAIN,
}
]
: []
}
}
})
TOKWORK_WEBSITE_ID=your-website-id
TOKWORK_DOMAIN=yourdomain.com
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<!-- tokwork Widget -->
<script async src="https://js.tokwork.com/loader.js"
data-website-id="YOUR_WEBSITE_ID"
data-website-domain="yourdomain.com">
</script>
</body>
</html>
Create a plugin to inject the script:
export default {
install: (app, options) => {
if (typeof window !== 'undefined') {
const script = document.createElement('script')
script.src = 'https://js.tokwork.com/loader.js'
script.async = true
script.setAttribute('data-website-id', options.websiteId)
script.setAttribute('data-website-domain', options.domain)
document.body.appendChild(script)
}
}
}
Register the plugin:
import { createApp } from 'vue'
import App from './App.vue'
import TokworkPlugin from './plugins/tokwork'
const app = createApp(App)
app.use(TokworkPlugin, {
websiteId: 'YOUR_WEBSITE_ID',
domain: 'yourdomain.com'
})
app.mount('#app')
Add to nuxt.config.js:
export default {
head: {
script: [
{
src: 'https://js.tokwork.com/loader.js',
async: true,
'data-website-id': 'YOUR_WEBSITE_ID',
'data-website-domain': 'yourdomain.com',
}
]
}
}
npm run dev✅ tokwork Widget loaded successfullyThe tokwork widget automatically handles SSR: