Hotjar records sessions before consent (WordPress, Shopify)
Hotjar loads and sets its cookies before visitors answer your cookie banner. How to check it in DevTools and make it wait on WordPress and Shopify.
Lukas Kontur · · 7 min read
Hotjar shows you heatmaps and recordings of how visitors use your site. To do that, its script watches clicks, scrolling and page changes from the moment it loads. If it loads before your cookie banner has been answered, it starts its work before the visitor had a say. This guide shows how to check that in your own browser, the usual reasons it happens on WordPress, WooCommerce and Shopify, and how to make Hotjar wait.
The symptoms
- A scan report lists trackers before consent with requests to
hotjar.comorhotjar.io, or cookies that start with_hj. - You see your own visit in Hotjar's recordings even though you never clicked the banner.
- Your banner says analytics only runs after consent, but
_hjSessionUser_cookies are already set on the first page.
You are not alone. In our scan of 97,304 EU websites, 31.1% (30,239 sites) set analytics cookies before the visitor made any consent choice (full study).
How to check it yourself
- Open a new private window in Chrome (three-dot menu, "New Incognito window") and press F12.
- In Network, tick Disable cache and type
hotjarin the filter box. - Load your site. Do not touch the banner.
- Look for
static.hotjar.com/c/hotjar-followed by a number (the script with your site ID),script.hotjar.com, or otherhotjar.comandhotjar.ioaddresses. Hotjar lists these domains in its own Content Security Policy guide. Any of them before a click means Hotjar started before consent. - In Application, Cookies, look for the cookies Hotjar documents, for example
_hjSessionUser_and_hjSession_followed by your site ID, and test cookies such as_hjTLDTest(Hotjar: cookies set by the tracking code). - Click a Hotjar request and open the Initiator tab. If it shows your page itself, the code is pasted into the theme or added by a plugin. If it shows
googletagmanager.com/gtm.js, it comes from your GTM container. - Click Reject, reload, and repeat steps 4 and 5. Nothing new from Hotjar should appear.
If your account has been moved to Contentsquare, also filter for cs.hotjar.io and look for cookies starting with cs. Hotjar explains that after the move "the tag is loaded from t.cs.hotjar.io" and that the cs and _hj cookie families can run in parallel (Hotjar: moving to Contentsquare).
Why it happens
- The code is pasted into the theme. Hotjar tells you to paste its tracking code into the page head. On Shopify, its instructions put it in
theme.liquid, "just before the closing</head>tag" (Hotjar: Shopify). Code placed there runs on every page as soon as it loads, unless something blocks it. - A WordPress plugin adds it without a consent check. The official Hotjar plugin only asks for your Hotjar Site ID (Hotjar: WordPress) and adds the code to every page. Its WordPress.org page shows that it has not been updated for a long time. Your consent plugin has to recognise and block it.
- Your consent plugin is told Hotjar needs no consent. Current Complianz versions ask whether Hotjar is configured in a privacy-friendly way. Complianz's article on the topic, last changed in 2019, says "You can use Hotjar before consent" if text and images that may contain personal data are suppressed (Complianz: configuring Hotjar). If you answered yes, Complianz may let Hotjar load before consent. Whether that answer fits your site is a legal question; Hotjar describes you as the data controller, "principally responsible for (among other things) collecting consent" (Hotjar: GDPR responsibilities).
- Google Tag Manager fires it on all pages. Hotjar's GTM instructions use the All Pages trigger and warn that other triggers stop it working correctly (Hotjar: Google Tag Manager). Without a consent setting on the tag, it fires for everyone.
- The move to Contentsquare added a new tag. Hotjar states that "the Contentsquare tag does not automatically read or inherit your existing cookie banner or Consent Management Platform (CMP) configuration" (moving to Contentsquare, linked above). A banner that blocked the old tag may not block the new one.
The fix on WordPress and WooCommerce
Step 1: keep one copy of the code
Search your theme, your snippet plugin and your GTM container for hotjar and _hjSettings (the settings object in the tracking code). Keep one copy. If you move the code to GTM, deactivate the Hotjar plugin.
Step 2a: Complianz
- In the Wizard, select Hotjar among the third-party services your site uses.
- Answer the follow-up question about a privacy-friendly configuration deliberately. If you want Hotjar to wait for consent, do not answer that it needs none.
- If Hotjar still loads, add
static.hotjar.comin the Script Center under "URLs that should be blocked before consent" and choose statistics (Complianz developer guide).
Step 2b: CookieYes
CookieYes names Hotjar among the third-party cookies it blocks (CookieYes: which third-party cookies are blocked). If it still loads, add a Script URL Pattern such as hotjar.com with the analytics category (CookieYes: prior consent), and make sure the CookieYes script is first in the page and excluded from optimisation plugins.
Step 2c: Google Tag Manager
Keep the All Pages trigger Hotjar asks for, then open the tag's Advanced Settings, Consent Settings, choose "Require additional consent for tag to fire" and add analytics_storage (Google: consent in Tag Manager). Google says such a tag fires only if the consent types are granted "when the tag is triggered". In practice, after a visitor clicks Accept, Hotjar starts on the next page they open. Your banner must send its choice to Google Consent Mode; see our GTM Consent Mode guide.
The fix on Shopify
Shopify holds back custom pixels until consent, and our Shopify pixels guide shows how. For Hotjar this is a poor fit: Shopify lists "clicks and mouse movement to create heatmaps from DOM scraping" and "page scrolling" among the things pixel sandboxes cannot detect (Shopify Help: pixels overview). So Hotjar usually stays in the theme, and the theme code has to check consent itself.
- Make sure Shopify knows the visitor's choice: either Shopify's own banner under Settings, Customer privacy, Cookie banner, or a consent app that syncs through the Customer Privacy API (Shopify Help: customer privacy settings).
- Go to Online Store, Themes, three dots, Edit code, open
theme.liquidand find the Hotjar code. - Wrap it so it only runs when analytics is allowed. The method and event names come from Shopify's Customer Privacy API reference:
<script>
(function () {
var loaded = false;
function loadHotjar() {
if (loaded) return;
loaded = true;
// Paste the inside of your Hotjar tracking code here (without its <script> tags).
}
window.Shopify.loadFeatures(
[{ name: 'consent-tracking-api', version: '0.1' }],
function (error) {
if (error) return;
if (window.Shopify.customerPrivacy.analyticsProcessingAllowed()) loadHotjar();
}
);
document.addEventListener('visitorConsentCollected', function (event) {
if (event.detail.analyticsAllowed) loadHotjar();
});
})();
</script>
Keep a copy of the original code before you change the theme, and test in the theme preview first. This only stops Hotjar from starting. If a visitor accepts and later changes their mind, it keeps running until the next page load. Our guide on Shopify Decline not being honoured explains this in more detail.
How to verify the fix
Use a new private window for each run, with Disable cache ticked:
- Before any click: the filter
hotjarshows nothing, and no_hjcookies are set. - After Reject and a reload, then a second page: still nothing from Hotjar.
- After Accept: Hotjar's script loads (with the GTM setup, from the next page on) and
_hjSessionUser_appears. Your new visit should show up in Hotjar as usual. - If your account moved to Contentsquare, repeat the three runs with the filter
cs.hotjar.io.
See also: How to test your cookie consent banner: a 10-minute manual check and an automated scan and Complianz with Google Tag Manager: making tags wait for consent (Consent Mode v2).
Background: Pre-consent tracking explained. If your banner leaks more than Hotjar, see My cookie plugin says compliant, but the scan disagrees.
Check your site in 1 minute
Our free scan loads your site in a clean browser, records which scripts and cookies run before the banner is answered, and shows the exact request that leaked. No signup needed. Run a free scan.
Get alerted when it breaks
A theme change or a new tag can put Hotjar in front of your banner again. With monitoring, we re-scan your site on a schedule and email you when a tracker starts running before consent. The free plan includes one monitored site with a weekly re-scan and email alerts. Create an account and add your site.
Last updated: