Jarhead for Craft CMS

Free · Craft 5.3+

Hotjar on every page, and off the ones you meant

Paste the Site ID from your Hotjar account and every front-end page gets the tracking code, with no template change. That part is easy — the WordPress plugin does it in one field. Jarhead does it too, and then does the four things that go wrong on the day after you install it.

Jarhead

One field, or one config file

The Site ID is per Craft site and read from the environment, so production and staging can point at different Hotjar accounts — or staging at none at all. An environment variable that is not set here reads back as “not configured”, never as a literal string.

php
// config/jarhead.php
return [
    'siteIds' => ['default' => '$HOTJAR_SITE_ID'],
    'allowedEnvironments' => ['production'],

    'excludeAdmins'   => true,
    'excludedGroups'  => ['editors', 'staff'],
    'uriRules'        => [
        ['pattern' => 'checkout/*', 'mode' => 'exclude'],
    ],

    'consentMode'        => 'cookie',
    'consentCookie'      => 'cookie_consent',
    'consentCookieValue' => 'substring:analytics',
];

Features

The tracking code is the easy part. These are the four things that go wrong afterwards, and the tools for when it looks like nothing is happening.

Not your own team

Hotjar bills by session, and an editor clicking through drafts is not a customer. Admins and previews are excluded out of the box; signed-in users, named groups and URI patterns are a setting away.

  • Globs, or regular expressions with a re: prefix
  • An exclusion always beats an inclusion, whatever the order

Staging stays out of it

One Site ID deployed everywhere is how a developer typing asdf into a checkout ends up in the same Hotjar account as your customers, with nothing in the data to tell them apart.

  • A Site ID per Craft site, read from the environment
  • jarhead/status --strict fails a deploy that would send nothing

Nothing until they say yes

Session recording is personal data — it is a video of somebody using your site. Under a consent gate there is no script element, no request to hotjar.com and no _hjSettings until the visitor agrees.

  • Cookie, DOM event, dataLayer (Consent Mode v2) or a manual call
  • Do Not Track and Global Privacy Control honoured on top

Recordings you can filter

Every Craft page already knows its section, entry type, template, site and language. None of it reaches Hotjar unless something sends it, so a recording with no attributes is a video you have to watch to find out whether it was relevant.

  • Custom attributes too, read from the environment
  • Never an email address and never a username, under any setting

Silence looks like success

Hotjar's CDN answers 200 for every numeric Site ID ever asked for — an ID that does not exist just gets an empty file. Jarhead reads the body, so a wrong ID is reported as wrong instead of ticked off.

  • Also reports recording switched off, or sampling below 100%
  • The real cause of most “installed but no recordings” tickets

Why is it not on that page?

Type a URI into the Hotjar utility and get back the first rule that applied, through the same code path a real request takes. The same answer is available in Twig and on the command line.

  • php craft jarhead/explain checkout/cart
  • {{ craft.jarhead.explain.message }} in a staging footer

Frequently Asked Questions

The questions worth answering before you install it.

Free, and about ten minutes to install

Paste a Site ID and you are recording. Set the environment allowlist and the consent gate before you deploy, and you are recording the right people.