Scripts

Hotjar is a screen recorder and heatmap tool that helps you understand how users interact with your website.

Script Stats

Transfer
6.1 KB
Decoded
14.7 KB
Loading
Dynamic
First-Party
Supported
Bundling
Supported
Privacy
Some data collected
Tracked Data
Page Views Session Replay Heatmaps Clicks Scrolls Form Submissions

Nuxt Config Setup

The simplest way to load Hotjar globally in your Nuxt App is to use Nuxt config. Alternatively you can directly use the useScriptHotjar composable.

export default defineNuxtConfig({
  scripts: {
    registry: {
      hotjar: {
        id: '1234567'
      }
    }
  }
})

useScriptHotjar

The useScriptHotjar composable lets you have fine-grain control over when and how Hotjar is loaded on your site.

const { proxy } = useScriptHotjar()

proxy.hj('event', 'conversion')

Please follow the Registry Scripts guide to learn more about advanced usage.

First-Party Mode

This script supports First-Party Mode which routes all traffic through your domain for improved privacy and ad blocker bypass.

export default defineNuxtConfig({
  scripts: {
    firstParty: true,
    registry: {
      hotjar: { id: '1234567'}
    }
  }
})

To opt-out for this specific script:

useScriptHotjar({
  id: '1234567',
  scriptOptions: {
    firstParty: false
  }
})

Example

Using Hotjar only in production while using the proxy to send events.

ConversionButton.vue
<script setup lang="ts">
const { proxy } = useScriptHotjar()

// noop in development, ssr
// just works in production, client
function handleAction() {
  proxy.hj('event', 'conversion')
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>

HotjarApi

export interface HotjarApi {
  hj: ((event: 'identify', userId: string, attributes?: Record<string, any>) => void)
  & ((event: 'stateChange', path: string) => void)
  & ((event: 'event', eventName: string) => void)
  & ((event: string, arg?: string) => void)
  & ((...params: any[]) => void) & {
    q: any[]
  }
}

Config Schema

You must provide the options when setting up the script for the first time.

export const HotjarOptions = object({
  id: number(),
  sv: optional(number()),
})