Vue Hotjar Next Plugin

2.1.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { createApp } from 'vue';
import App from './App.vue';
import VueHotjar from 'vue-hotjar-next';

const app = createApp(App);

app.use(VueHotjar, {
  id: process.env.VUE_APP_HOTJAR_ID ?? 12345678,
  isProduction: process.env.NODE_ENV === 'production',
  snippetVersion: 6
});

app.mount("#app");

// Example of accessing Hotjar Identify API globally or in a component (after setup)
// In a component (Options API):
// export default {
//   mounted() {
//     this.$hj('identify', 'USER_ID', { userProperty: 'value' });
//   }
// };

// In a component (Composition API):
// import { getCurrentInstance } from 'vue';
// const instance = getCurrentInstance();
// instance.appContext.config.globalProperties.$hj('identify', 'USER_ID', { userProperty: 'value' });

view raw JSON →