Hotjar and Clarity Performance: Record Fewer Sessions

A session recorder runs about 100 ms of code on every visit. Load it only for the sessions you need.

  • Good ≤ 200 ms
  • Needs improvement ≤ 500 ms
  • Poor > 500 ms
Arjen Karel
Updated · 5 min read
Share

Hotjar and Microsoft Clarity performance in short

On a phone, a session recorder runs about 100 ms of main thread work per visit, mostly a few seconds after the visitor clicks "Accept". It can delay clicks (INP), not LCP. Decide what you want to record, then load Hotjar or Clarity for a share of sessions. The other sessions skip that work.

Does Hotjar or Microsoft Clarity slow down your site?

Yes, a little on every visit, and more when you run both. We measured seven sites on a simulated phone (Slow 4G, 4x slower CPU). On the first page after consent, Clarity ran 90 to 120 ms of code and Hotjar 27 to 240 ms, depending on the site. Each visit had at most two long frames of 50 to 110 ms. LCP did not change on any of them.

A click during one of those frames has to wait for the JavaScript to finish. Clicks that change much of the page also wait while the recorder processes the change: 17 ms for 100 new list items and 70 ms for 500 in Highlight's open benchmark. Our test clicks changed little. In CoreDash field data the recorder is the main script in 1 to 3% of interactions with a long frame, and those are slower: on one store their p75 was 176 ms, against 115 ms for all interactions.

Clarity's FAQ says visitors notice no change in speed. I would call that opportunistic marketing, because it is just not the reality. The work after consent shows up in INP. Contentsquare, which owns Hotjar, lists INP as affected, with 25 to 100 ms of extra blocking time on mobile.

Other articles quote 405 ms for Clarity and 732 ms for Hotjar from third-party-web. That is the mean of mobile Lighthouse runs on more than 500,000 pages each. Pages with a large DOM raise that mean. Ours are medians per site.

How do you fix Hotjar and Clarity performance?

A session recorder is not slow by mistake, it is slow by design: someone chose to install it, and that is not wrong in itself. So the fix starts with the goal, not with code. What do you want to learn from the recordings, and who watches them? These tools almost always do far more than that goal needs: they record every visitor on every page, while the team watches a small part of it. Once the goal is clear, you set the tool up to reach it without slowing the page: record fewer sessions, and start the recorder later.

  1. Find out why it is there. On client sites I ask this first. Sometimes the recordings matter for the business, and then they stay. More often two departments each installed a recorder and hardly talk, or it was set up once and never thought about again. Then ask what the team uses today. When the recordings don't serve the site's business goals, one recorder can go or the two can become one.
  2. Record only what the goal needs. Load the recorder on the pages you study, remove it when the question is answered, and turn off unused Hotjar feedback and survey widgets.
  3. Load the recorder for a share of sessions. Neither tool has a sample rate setting, so the script below picks the sessions, once per session, because a page view without the Hotjar tag ends a recording.
  4. Put it where the vendor snippet was. Fill in your IDs and remove the old snippet. In Google Tag Manager it is a Custom HTML tag on the same consent trigger.
<script>
// Load Microsoft Clarity and/or Hotjar for a share of sessions, after the page has loaded.
(function () {
  var RATE = 0.5;                 // share of sessions that are recorded
  var CLARITY_ID = 'YOUR_CLARITY_ID'; // the ID at the end of your Clarity snippet, '' when you don't use Clarity
  var HOTJAR_ID = 0;              // hjid in your Hotjar snippet, 0 when you don't use Hotjar
  var HOTJAR_SV = 6;              // sv in that snippet: 6, or 7 on Hotjar's newer (Contentsquare) build

  // Decide once per session (per tab: sessionStorage), so the recording keeps going on the next page.
  var record;
  try {
    record = sessionStorage.getItem('recorder-sample');
    if (record === null) {
      record = Math.random() < RATE ? '1' : '0';
      sessionStorage.setItem('recorder-sample', record);
    }
  } catch (e) {
    record = '0'; // no sessionStorage: don't record
  }
  if (record !== '1') return;

  function load() {
    if (CLARITY_ID) {
      (function (c, l, a, r, i, t, y) {
        c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments); };
        t = l.createElement(r); t.async = 1; t.src = 'https://www.clarity.ms/tag/' + i;
        y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y);
      })(window, document, 'clarity', 'script', CLARITY_ID);
    }
    if (HOTJAR_ID) {
      (function (h, o, t, j, a, r) {
        h.hj = h.hj || function () { (h.hj.q = h.hj.q || []).push(arguments); };
        h._hjSettings = { hjid: HOTJAR_ID, hjsv: HOTJAR_SV };
        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=');
    }
  }

  // Start after the load event, when the browser has nothing else to do.
  function whenIdle() {
    if ('requestIdleCallback' in window) requestIdleCallback(load, { timeout: 3000 });
    else setTimeout(load, 1000); // Safari
  }
  if (document.readyState === 'complete') whenIdle();
  else addEventListener('load', whenIdle, { once: true });
})();
</script>

Starting after the load event keeps the recorder out of page loading on later pages and on sites that load it before consent, but the sampling makes the big difference.

You lose the recordings and heatmaps of skipped sessions. Clarity records at most 100,000 sessions per project a day, but its script still runs for every visitor.

Why does a session recorder slow down the page?

To replay a visit, it first copies the page: the DOM, element sizes and styles. Reading sizes makes the browser calculate the layout right away (a forced reflow). In our traces, most of Clarity's later callbacks were forced reflows.

Most people think an async recorder is free. Async only keeps the download from blocking the HTML parser. The code still runs on the main thread, like your click handlers. Behind a consent banner on a slow connection, it runs 3 to 8 seconds after "Accept", just when the visitor starts using the page. Hotjar's help suggests loading the tag on the first click or scroll. That click only adds the script tag. The start-up work comes after the download, during the next clicks and scrolls.

How do you check that sampling worked?

In CoreDash, look at the mobile interactions where clarity.ms or hotjar.com is the main script. With a rate of 0.5 their share should halve within a few days, and your Clarity dashboard shows about half the recordings.

If INP on mobile is still red after this, Core Web Vitals consultancy is the next step: I work out with your team which tags the site needs.

About the author

Arjen Karel is a web performance consultant and the creator of CoreDash, a Real User Monitoring platform that tracks Core Web Vitals data across hundreds of sites. He also built the Core Web Vitals Visualizer Chrome extension. He has helped clients achieve passing Core Web Vitals scores on over 925,000 mobile URLs.

Arjen Karel

Need a faster site?

I'm Arjen, and I've been fixing slow sites for 17 years. If you're running into issues you can't fix yourself, send me your URL and let's have a chat.

Send me your URL
Arjen Karel
Arjen Karel, Web performance consultant since 2009

Why isn't our fix working?

Sometimes the CDN still serves the old HTML, or the fix went into the desktop template and mobile uses another one. Send me your URL and the problem, and I reply with a few times. I check your field data first, then we spend one hour on your site, and within a day you have my notes in writing. €350 excl. VAT.

Send me your URL

No developer to build the fix? I do the work myself, on a copy of your site.

Arjen KarelINP still red on mobile?Send me your URL