轻松将Hotjar添加到您的 Nuxt 应用程序,用于跟踪和分析。
npx nuxi@latest module add hotjar
将 nuxt-module-hotjar 添加到 nuxt.config.ts 的 modules 部分,并提供您的 Hotjar 站点 ID 和脚本版本。
为了让 Nuxt Hotjar 运行,需要使用您的站点 ID 进行初始化(这就是我们模块中的 hotjarId)。您可以在此页面上,在您的站点名称前面找到您的站点 ID。
export default defineNuxtConfig({
modules: [
'nuxt-module-hotjar'
],
hotjar: {
hotjarId: 1234567,
scriptVersion: 6,
// optionally you can turn on debug mode for development
debug: true
}
})
现在您必须使用可组合函数 useHotjar 在您的应用程序中初始化 Hotjar
// In you app.vue file for example when you user has given consent:
const { initialize } = useHotjar()
function onConsent() {
initialize()
}
useHotjarSSR 安全的 useHotjar 可组合函数提供对以下内容的访问
您可以像这样使用它
const { initialize } = useHotjar()
function useHotjar(): {
initialize: () => void
}
| 选项 | 类型 | 默认 | 描述 |
|---|---|---|---|
hotjarId | number | 未定义 | 您的 Hotjar site_id。 |
scriptVersion | number | 6 | 默认是 6,您不一定需要更改它。 |
调试 | boolean | false | 调试模式 |
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release