Vue Hotjar Next is a plugin designed for integrating Hotjar analytics seamlessly into Vue 3 applications. Currently stable at version 2.1.0, the package follows an as-needed release cadence, with significant updates like the v2.0.0 major refactor improving API access and type safety. Key differentiators include its exclusive compatibility with Vue 3 (requiring `vue-hotjar` for Vue 2 projects), providing direct access to the Hotjar Identify API and configuration settings via Vue's global properties (`$hj` and `$hjSettings`). This approach allows developers to interact with Hotjar functions like `hj('identify', ...)` through `$hj` without directly manipulating the `window.hj` object, offering a more Vue-idiomatic integration. It also ships with TypeScript types, ensuring robust development.
npm install vue-hotjar-nextVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install and initialize the `vue-hotjar-next` plugin in a Vue 3 application, including configuration for the Hotjar ID, production environment, and snippet version. It also hints at how to access the `$hj` global property for Hotjar's Identify API.
For Vue 2 projects, use the `vue-hotjar` package. For Vue 3, ensure your project's Vue version is 3.x.x.
Migrate your Hotjar API calls from `window.hj` to `app.config.globalProperties.$hj` (or `this.$hj` in components). Similarly, access settings via `app.config.globalProperties.$hjSettings`.
Always explicitly configure `isProduction`, typically by binding it to your Node environment variable, e.g., `isProduction: process.env.NODE_ENV === 'production'`.
If using a string ID, ensure you are on `vue-hotjar-next` version 2.1.0 or later to guarantee full compatibility and correct validation.
Ensure your project is running Vue 3. If you need Hotjar for Vue 2, use the `vue-hotjar` package instead.
Add a declaration file (e.g., `vue-hotjar-next.d.ts`) to augment the `ComponentCustomProperties` interface with `$hj: HotjarPlugin;` and `$hjSettings: HotjarSettings;`.
Verify `isProduction` is `true` in your configuration, double-check your Hotjar Site ID, and inspect your browser's network tab to confirm the Hotjar script (`static.hotjar.com/c-v.js`) is loaded without errors.