Skip to main content

Replay and monitoring

Hotjar

Hotjar records what visitors do on your pages, so it should load only when consent allows analytics. The c15t hotjar helper waits until the measurement category is allowed before it adds the Hotjar loader. Until then, c15t doesn't define window._hjSettings or window.hj, and it loads nothing from Hotjar. Under an opt-in policy, that wait lasts until the visitor allows analytics.

Withdrawal needs more care. c15t sends Hotjar no consent signal, so it can't tell a running recording to stop. By default it reloads the page instead, and the reload ends the recording.

Configure Hotjar

Find your site ID in the Hotjar tracking code. It's the hjid value. Then delete the tracking code from your app. c15t doesn't control that snippet, so if it stays, Hotjar loads and records even after the visitor rejects analytics.

npm install @c15t/integrations
src/consent-scripts.ts
import { hotjar } from '@c15t/integrations/hotjar';

export const scripts = [hotjar({ siteId: 1234567 })];

Register the scripts

Complete your framework quickstart first. Keep its Inth endpoint, policy, styles and consent UI. Remove the vendor's original script, SDK initializer or tag-manager entry, so the vendor loads only through c15t.

The vendor pages put the helper in src/consent-scripts.ts. If your framework quickstart already has a scripts array, such as the one in c15t.config.ts in the Next.js guide, add the helper to that array instead of creating a second file. The scripts export is a configuration, not an initializer. Add it to the c15t provider you already have, at the registration point for your framework below. These are edits to that provider, not a second provider.

Add the configuration to scripts in c15t.config.ts, next to next.config.ts:

import { defineConsentConfig } from 'c15t/next';
import { scripts } from './src/consent-scripts';

export default defineConsentConfig({ scripts });

Keep the rest of your config, such as mode and routePrefix, in the same call. ConsentRoot reads the config in the browser, so the layout keeps passing only state. App Router, Pages Router and static export all read the same file. See Next.js scripts and embeds.

Options

OptionDefaultBehavior
siteIdRequiredSite ID as a number or string. Set as window._hjSettings.hjid and used in the default loader URL. If it's missing, empty or 0, c15t logs an error and never loads Hotjar.
version6Script version, set as window._hjSettings.hjsv and the sv query parameter of the default loader URL.
scriptUrlhttps://static.hotjar.com/c/hotjar-<siteId>.js?sv=<version>Loader URL override.

Loading and revocation

hotjar uses the measurement category. When measurement is allowed, the helper sets window._hjSettings and a window.hj stub that queues calls, then loads the Hotjar script. If your page already defines either global, the helper leaves it alone.

When the visitor withdraws, the helper removes the script element. Hotjar is already running by then, so removing the element doesn't stop it. The default page reload does. If you set reloadOnConsentRevoked: false, Hotjar keeps recording until the visitor leaves the page.

Verify Hotjar

Filter the DevTools Network panel by hotjar. After you allow measurement, the loader appears and window._hjSettings.hjid holds your site ID. If it holds a different ID, other code on the page set _hjSettings before c15t, and the helper left it alone. Find and remove that code. By default the loader is hotjar-<siteId>.js from static.hotjar.com. If you set scriptUrl, look for that URL instead.

Then watch one recording of a real screen in your app. Hotjar decides what to mask, not c15t, so check that it hides the fields you expect.

window.hj stays defined after withdrawal. If your own code calls hj(), check the measurement permission first.

Test in a private window with an opt-in policy. Open DevTools Network, disable the cache and filter by the vendor's domain:

  1. Load the page. No request goes to the vendor before you choose.
  2. Click Reject, then reload. There is still no vendor request.
  3. Open Privacy settings and allow the helper's category. The vendor script loads without a page reload.
  4. Turn the category off again and save. c15t reloads the page, and the new page makes no vendor request.

c15t reloads on revocation because removing a script element does not stop code that already ran. The vendor's listeners, timers and queued events stay alive until the page unloads. If you set reloadOnConsentRevoked: false, stop the vendor yourself. Register a callback-only script whose onConsentChange calls the vendor's opt-out API, as shown in custom integrations, and check the permission before each of your own event calls. The reload does not delete cookies the vendor already set; see clear on revocation for your framework.

The helper lists its vendor by name in the preference dialog, so a visitor can turn it off inside an allowed category. See vendor consent for your framework. The consent verification guide covers navigation, expiry and hosting checks.