Introduction
Updated for 2026 compliance practices.
Hotjar Vue cookie consent is a practical compliance topic for website owners validating consent, tags, and disclosures. If you run a Vue.js application and use Hotjar for analytics, feedback, or session recordings, you need to manage cookie consent correctly under GDPR. This guide walks you through the technical implementation, common pitfalls, and how to verify your setup with GDPRChecker. We cover consent defaults, pre-consent network requests, tag manager triggers, policy disclosures, Reject-flow testing, and post-change scans. Remember, this is technical implementation guidance, not legal advice.
What Hotjar Vue Cookie Consent Means for Website Owners
Hotjar Vue cookie consent refers to the process of obtaining and respecting user consent before loading Hotjar tracking scripts in a Vue.js application. Hotjar sets cookies and processes personal data (such as IP addresses and user behavior), so under GDPR you typically need explicit consent before activating it. This means your Vue app must block Hotjar until the user has given a clear affirmative action, and you must provide a way to withdraw consent. See EDPB Guidelines 05/2020 on consent.
For Vue developers, this involves integrating a consent management platform (CMP) or building a custom consent mechanism that controls when Hotjar is initialized. The key challenge is that Hotjar's standard installation snippet often loads immediately, which can set cookies before consent is obtained. You need to modify this behavior to be consent-aware.
Why It Matters
Non-compliance can lead to fines and loss of user trust. Beyond legal risk, respecting consent improves transparency. Many website owners use Hotjar alongside Google Analytics or Google Consent Mode, so a consistent consent strategy is essential. For example, if you use Google Consent Mode v2, you'll want Hotjar to respect the same consent signals. This guide helps you close the consent gap for Hotjar in Vue, ensuring your site meets regulatory expectations.
Requirements and Compliance Expectations
Under GDPR, consent must be freely given, specific, informed, and unambiguous. For Hotjar, this means:
- Prior consent: Hotjar scripts must not load or set cookies before the user consents.
- Granular choice: Users should be able to accept or reject tracking separately if other purposes are involved.
- Easy withdrawal: Users must be able to change their mind and opt out later.
- Documentation: You need to disclose the use of Hotjar in your privacy policy, including what data is collected and why.
Regulatory guidance from the European Data Protection Board (EDPB) emphasizes that cookie walls (forcing consent for access) are not valid consent. Your Vue app should function without Hotjar if the user declines. Additionally, if you use Google Consent Mode, you may need to integrate Hotjar with its consent state to ensure tags fire appropriately. The GDPR.eu overview provides further details on consent requirements.
Technical Requirements
From a technical standpoint, you must:
- Block Hotjar's tracking script and cookies by default.
- Only initialize Hotjar after valid consent is recorded.
- Respect the consent state on subsequent page loads (e.g., by checking a cookie or localStorage flag).
- Ensure that any data sent to Hotjar is pseudonymized or minimized where possible.
How to Implement Hotjar Cookie Consent in Vue Step by Step
Implementing Hotjar cookie consent in Vue involves several steps. We'll assume you have a Vue 3 project (though Vue 2 is similar) and a basic consent banner. You can use a CMP like Cookiebot or build a custom solution. Here's a practical approach:
Step 1: Choose a Consent Management Strategy
You have two main options:
- Use a third-party CMP: Many CMPs offer Vue plugins or vanilla JS integration. They handle consent storage and can fire callbacks when consent changes.
- Build a custom consent layer: Create a Vue component for the banner, store consent in localStorage or a cookie, and control script loading manually.
For this guide, we'll build a custom solution to illustrate the mechanics. However, if you use Google services, consider a Google-certified CMP to align with Consent Mode v2. Our guide on Google Consent Mode v2 explains the benefits.
Step 2: Create a Consent State in Vue
Set up a reactive consent state using Vue's composition API or a store like Pinia. For example:
// stores/consent.js
import { ref } from 'vue';
export const useConsentStore = () => {
const analyticsConsent = ref(false);
const setConsent = (value) => {
analyticsConsent.value = value;
localStorage.setItem('analytics_consent', value);
if (value) {
// Initialize Hotjar here
} else {
// Disable Hotjar
}
};
// Check stored consent on app load
const stored = localStorage.getItem('analytics_consent');
if (stored === 'true') {
analyticsConsent.value = true;
// Initialize Hotjar
}
return { analyticsConsent, setConsent };
};
This store manages consent and triggers Hotjar initialization.
Step 3: Build a Consent Banner Component
Create a Vue component that displays the banner until consent is given. It should have Accept and Reject buttons, and possibly a link to the privacy policy. When the user clicks Accept, call setConsent(true). On Reject, call setConsent(false).
<template>
<div v-if="!consentDecided" class="consent-banner">
<p>We use Hotjar to improve our site. By accepting, you allow us to collect analytics data. <a href="/privacy">Learn more</a>.</p>
<button @click="accept">Accept</button>
<button @click="reject">Reject</button>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { useConsentStore } from '@/stores/consent';
const consentDecided = ref(localStorage.getItem('analytics_consent') !== null);
const { setConsent } = useConsentStore();
const accept = () => {
setConsent(true);
consentDecided.value = true;
};
const reject = () => {
setConsent(false);
consentDecided.value = true;
};
</script>
This ensures the banner only shows until a decision is made.
Step 4: Conditionally Load Hotjar
Hotjar provides a tracking code that you normally place in your HTML. To make it consent-aware, you must not load it until consent is given. One method is to dynamically inject the script.
Create a function that loads Hotjar:
// utils/hotjar.js
export function loadHotjar(hjid, hjsv) {
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid,hjsv};
a=o.getElementsByTagName('head')[0];
r=o.createElement('script');r.async=1;
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
}
Call this function only when analyticsConsent is true. In your consent store, after setting consent to true, call loadHotjar(YOUR_HJID, YOUR_HJSV). Also, on app mount, if stored consent is true, call it.
Step 5: Handle Consent Withdrawal
Users must be able to withdraw consent. Provide a link or button (e.g., "Cookie Settings") that reopens the banner or a settings panel. When they opt out, you need to disable Hotjar. Unfortunately, Hotjar doesn't have a built-in opt-out function that removes already set cookies, but you can:
- Delete Hotjar cookies (
_hj*). - Set a flag to prevent future loading.
- Optionally, call
window.hj('trigger', 'optOut') if available.
Update your consent store to handle withdrawal:
const withdrawConsent = () => {
analyticsConsent.value = false;
localStorage.setItem('analytics_consent', false);
// Delete Hotjar cookies
document.cookie.split(';').forEach(c => {
if (c.trim().startsWith('_hj')) {
document.cookie = c.trim().split('=')[0] + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
}
});
// Reload or notify user
};
Step 6: Integrate with Google Consent Mode (Optional)
If you use Google Consent Mode, you can tie Hotjar loading to the consent state for analytics. For example, when analytics_storage is granted, load Hotjar. This ensures consistency across tools. Our Google Consent Mode v2 guide details the setup.
Common Mistakes and How to Avoid Them
Many implementations fail due to subtle issues. Here are the most frequent mistakes:
1. Hotjar Loads Before Consent
The default Hotjar snippet is often placed in the <head> and loads immediately. Even if you have a consent banner, the script may fire before the user interacts. Always remove the default snippet and load it dynamically after consent.
2. Not Blocking Pre-Consent Network Requests
Even if you delay Hotjar's main script, other tags (like Google Tag Manager) might load Hotjar based on triggers. Ensure that your GTM triggers for Hotjar are set to fire only on consent. Use GTM's consent initialization or custom events. Our Google Analytics GDPR compliance guide covers similar patterns.
3. Ignoring Reject-Flow Testing
Many developers test only the Accept path. You must verify that when a user rejects, no Hotjar cookies are set, and no network requests to Hotjar domains occur. Use browser DevTools to check the Network tab and Application > Cookies.
4. Incomplete Privacy Policy Disclosures
Your privacy policy must mention Hotjar, the data it collects, and its purpose. If you use Hotjar's session recordings, you need to disclose that and possibly mask sensitive fields. Failing to update your policy is a common gap. Use our cookie banner requirements guide to ensure your banner and policy align.
5. Not Handling Consent on All Pages
If your Vue app uses client-side routing, consent state should persist across route changes. Use a global store and check consent on each navigation if needed. Also, ensure that Hotjar isn't re-initialized on every route change unless necessary.
6. Overlooking Third-Party Dependencies
Sometimes Hotjar is loaded via a plugin or a third-party service. Audit all your dependencies to ensure none load Hotjar without consent. This is where a scanner like GDPRChecker becomes invaluable.
How to Validate Hotjar Vue Cookie Consent with GDPRChecker
After implementing consent, you must verify that it works correctly. Manual testing is error-prone, so use GDPRChecker's scanner to automate checks. Here's how:
Pre-Scan Preparation
- Clear your browser cookies and cache.
- Ensure your consent banner is visible and functional.
- Have your privacy policy URL ready.
Running a Scan
- Go to GDPRChecker and start a new scan for your Vue site.
- The scanner will crawl your pages, simulating a first-time user without consent.
- It checks for pre-consent network requests, cookies set, and disclosures.
What to Look For
- Pre-consent requests: The scanner flags any requests to
hotjar.com or related domains before consent. If you see these, your blocking isn't working. - Cookie audit: It lists all cookies, including
_hj* cookies. They should only appear after consent. - Banner behavior: The scanner verifies that the banner is present and that rejecting actually prevents tracking.
- Disclosure gaps: It checks your privacy policy for mentions of Hotjar and its purpose.
Post-Change Scans
Whenever you update your consent logic, run a new scan. This catches regressions. GDPRChecker helps close the Cookie Banner gap, the Consent Mode gap, and the Privacy Policy gap in one workflow. For more on consent mode gaps, see our Consent Mode v2 vs Google Certified CMP guide.
Implementation Checklist
Use this checklist to ensure your Hotjar Vue cookie consent setup is complete:
- Remove the default Hotjar snippet from your HTML.
- Create a consent state in Vue (e.g., using Pinia or composables).
- Build a consent banner with clear Accept and Reject buttons.
- Link to your privacy policy from the banner.
- Dynamically load Hotjar only after consent is granted.
- Store consent decision in localStorage or a cookie.
- On app load, check stored consent and load Hotjar if previously accepted.
- Implement consent withdrawal: delete Hotjar cookies and prevent reloading.
- Ensure Google Tag Manager triggers for Hotjar respect consent signals.
- Update your privacy policy to disclose Hotjar usage and data collection.
- Test the Reject flow: verify no Hotjar cookies or network requests.
- Run a GDPRChecker scan to validate pre-consent blocking and disclosures.
- Re-scan after any changes to consent logic or third-party scripts.
FAQ
What is Hotjar Vue cookie consent?
Hotjar Vue cookie consent is the practice of obtaining user permission before loading Hotjar tracking scripts in a Vue.js application. It ensures compliance with GDPR by blocking cookies and data collection until the user explicitly agrees.
Do I need Hotjar Vue cookie consent for GDPR?
Yes, if your Vue site uses Hotjar and serves users in the EU/EEA, you generally need prior consent because Hotjar sets non-essential cookies and processes personal data. Consent must be obtained before any tracking occurs.
How do I implement Hotjar Vue cookie consent?
Implement by creating a consent banner in Vue, storing the user's choice, and dynamically loading the Hotjar script only after consent. Use a state management solution to control loading and handle consent withdrawal.
How can I verify Hotjar Vue cookie consent with a scanner?
Use GDPRChecker to scan your site. It checks for pre-consent network requests to Hotjar, cookie placement, banner presence, and privacy policy disclosures. Run scans before and after consent to validate blocking.
What are common Hotjar Vue cookie consent mistakes?
Common mistakes include loading Hotjar before consent, not testing the reject flow, incomplete privacy policy disclosures, and failing to block Hotjar in Google Tag Manager. Regular scanning with GDPRChecker helps catch these issues.
Next Steps for Compliance
Implementing Hotjar cookie consent in Vue is a critical step, but it's part of a broader compliance strategy. Ensure you also address Google Analytics consent, cookie banner requirements, and overall privacy policy gaps. Use GDPRChecker to continuously monitor your site and close compliance gaps. Start a scan today to verify your Hotjar setup and protect user privacy.
Copyright and editorial notice
© GDPRChecker
This original AI-assisted editorial draft was selected, reviewed, and published by GDPRChecker. All rights are reserved where protected by applicable law. Do not reproduce the article without permission.