henk-badenhorst / vue-hotjar

A NPM package to easily integrate Hotjar to any Vue 2 Project
https://www.npmjs.com/package/vue-hotjar
MIT License
27 stars 3 forks source link
analytics hotjar plugin vue



     

Vue Hotjar

This is a VueJs plugin that will allow you to easily add Hotjar to any Vue project. Some key benefits allow you to activate or deactivate tracking based on the environment and in some more advanced use cases you have access to $hj. This is a global property that gives you access to the identify API and other functions to pass data to Hotjar.

Install

npm install vue-hotjar

Start using it in your Vue application.

import Vue from 'vue'
import Hotjar from 'vue-hotjar'

Vue.use (Hotjar, {
  id: 'XXXXXXX' // Hotjar Site ID
})

Parameters

Id:

Your Hotjar Site ID is a required parameter. You can find this ID at insights.hotjar.com under tracking.

id: 'XXXXXXX' 

isProduction:

If you would like to disable or enable tracking, pass in either true or false. It is advised to bind your Node ENV variable. This is an optional parameter and will default to true if not specified.

isProduction: true 

snippetVersion:

This optional parameter does not need to be specified as it will default to the latest Hotjar Snippet version. Currently, it will default to version 6.

snippetVersion: 6 

Full Example

import Vue from 'vue'
import Hotjar from 'vue-hotjar'

Vue.use (Hotjar, {
  id: 'XXXXXXX',
  isProduction: true,
  snippetVersion: 6
})

Verify Installation

In order to verify your installation in a production environment or whenever the isProduction parameter is set to true, you can simply navigate to the below URL. If the installation is successful you should see a notification appear on your website indicating that Hotjar is receiving data and your implementation is successful.

https://<YOUR-BASE-URL>/?hjVerifyInstall=<YOUR-SITE-ID>

Additionally you can verify the install by logging in to insights.hotjar.com and view the tracking status.

HotJar API

instead of accessing HotJar through window.hj you can simply interact with the API via the a Vue global property $hj.

Important To Note:

Track Changes Manually

if (this.$hj) {
  this.$hj('stateChange', '/your/url/here')
}

Virtual Page View

if (this.$hj) {
  this.$hj('vpv', 'funnel-step-one')
}

Identify API (Business Plan)

if (this.$hj) {
  this.$hj('identify', userId, {
    email: 'hello@coffeeshop.com',
    purchase_amount: 500,
    ab_test: 'variant-A',
  })
}

Supported Vue Versions