Analytics
PostHog
Configure PostHog
Use the project token that starts with phc_, and the region of your PostHog
project. This example waits for measurement permission before requesting the
SDK, and turns off cookieless capture after a refusal.
The helper initializes PostHog itself. Remove any posthog-js initializer,
framework plugin or array snippet that also does, or follow
use an existing PostHog SDK instead.
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:
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
| Option | Default | Behavior |
|---|---|---|
id | Required | Project token, starting with phc_. The helper trims it. Empty or whitespace-only values log an error and the script does not load. |
region | 'eu' | 'eu' or 'us'. Picks the API, UI and loader hosts when you do not set them. |
apiHost | https://eu.i.posthog.com | API host for a proxy or self-hosted PostHog. Without scriptUrl, the loader URL becomes <apiHost>/static/array.js. |
uiHost | The region's UI host | UI host, for example https://eu.posthog.com. A custom apiHost with no region uses the API host. |
scriptUrl | https://eu-assets.i.posthog.com/static/array.js | Loader URL override. A blank value falls back to the default. |
loadMode | 'always' | When the SDK loads. See the table below. |
features.surveys | Unset | false sets disable_surveys: true and skips surveys.js. See turn off features you do not use. |
features.heatmaps | Unset, follows the project | Sets capture_heatmaps. |
features.deadClicks | Unset, follows the project | Sets capture_dead_clicks. |
features.webVitals | Unset, follows the project | Sets capture_performance: { web_vitals }. Replay network timing keeps following the project. |
features.featureFlags | Unset, follows the project | false sets advanced_disable_feature_flags: true and stops /flags requests. |
initOptions | { cookieless_mode: 'on_reject', defaults: '2026-01-30' } | Options passed to posthog.init, merged over the defaults and features. The helper sets api_host and ui_host after your values, so change hosts with the options above. |
Loading and revocation
loadMode | When PostHog loads | Consent sync |
|---|---|---|
'always' | On every page, before consent | Calls opt_in_capturing or opt_out_capturing at load and on every change |
'after-consent' | Only while measurement is allowed | Calls opt_in_capturing at load and opt_out_capturing on revocation |
'disabled' | Never | None. The helper returns an empty callback-only script |
posthog uses the measurement category. With the default
cookieless_mode: 'on_reject', PostHog keeps capturing without cookies after a
refusal. That mode needs cookieless server hashing turned on in your PostHog
project; see
PostHog's cookieless guide.
Set cookieless_mode: 'never', as in the example, if a refusal must stop
capture.
Turn off features you do not use
After array.js loads, PostHog reads your posthog.init options and the
project's remote config, then decides which extra modules to download and
whether to request /flags. Set a features switch to false for each
feature your site does not use:
| Switch | false sets | What PostHog skips |
|---|---|---|
surveys | disable_surveys: true | surveys.js, about 29 KB |
heatmaps | capture_heatmaps: false | Heatmap capture. With deadClicks: false too, dead-clicks-autocapture.js |
deadClicks | capture_dead_clicks: false | dead-clicks-autocapture.js, about 8 KB, once heatmaps are off too |
webVitals | capture_performance: { web_vitals: false } | web-vitals-with-attribution.js, about 6 KB |
featureFlags | advanced_disable_feature_flags: true | /flags requests. The remote config still loads |
Sizes are brotli-compressed, measured from posthog-js 1.436.1.
An unset switch adds nothing to posthog.init. For heatmaps, dead clicks, web
vitals and feature flags, PostHog then follows the setting in your PostHog
project. true sets the opposite value and overrides the project. For
surveys and featureFlags, true is PostHog's own default, so it behaves
the same as unset.
Surveys work differently. PostHog downloads surveys.js whenever the remote
config includes a surveys value, even when surveys are off in the project.
surveys: false is the only way to skip it.
initOptions wins over a switch that sets the same key. A
capture_performance value in initOptions replaces the whole object that
webVitals builds.
Avoid PostHog's option traps
These rules also apply when you pass PostHog options yourself, in
initOptions or in your own posthog.init:
- Use
advanced_disable_feature_flags: trueto stop/flags, notadvanced_disable_flags: true. The second also stops PostHog loading the remote config, so session replay never starts and other features fall back to local config. - With feature flags off, surveys that target a feature flag never show.
PostHog logs a warning about it. If you need those surveys, leave
featureFlagsunset and passadvanced_only_evaluate_survey_feature_flags: trueinstead. PostHog still requests/flags, but evaluates only survey flags. - While heatmaps are on, in
posthog.initor in the project, PostHog loadsdead-clicks-autocapture.jswhatevercapture_dead_clickssays. Turn off both to skip it. capture_performance: falseturns off web vitals and session replay network timing.{ web_vitals: false }, whichwebVitals: falsesets, leaves network timing to the project.capture_performance: trueforces both on.
Product tours (product-tours.js, about 36 KB) and exception autocapture
(exception-autocapture.js, about 6 KB) load only when the project turns them
on. To keep them off whatever the project says, pass
disable_product_tours: true or capture_exceptions: false in initOptions.
Guard your own capture calls
Events your code sends need their own permission check. The posthog global
exists before the SDK loads, so its presence does not mean measurement is
allowed:
Pass the current measurement permission from your framework, for example
useConsent('measurement') in React.
Use an existing PostHog SDK
If your app already initializes posthog-js, keep that setup and register a
callback-only script instead of the helper. Initialize the SDK with
opt_out_capturing_by_default: true and cookieless_mode: 'never' so it
captures nothing before c15t reports a permission.
Add posthogConsent(posthog) to the scripts you register, passing your
initialized SDK instance. callbackOnly means c15t inserts no script element.
alwaysLoad makes onBeforeLoad run on the first page load even while
measurement is denied, so the SDK is told to opt out. onConsentChange runs on
every later change. This does not delay the SDK import or its first request.
loadMode: 'disabled' is not a substitute, because it syncs nothing.
features belongs to the helper, so it does nothing here. To skip modules you
do not use, pass the PostHog options from
turn off features you do not use to your
own posthog.init, for example disable_surveys: true.
Measure opt-in rate
If you run a banner experiment, the backend already counts visitors and
choices per arm. To see the arm in PostHog as well, forward the onSurfaceShown and
onChoiceRecorded callbacks, which carry experiment: { id, arm }. See
banner experiments.
Verify PostHog
These checks assume loadMode: 'after-consent' from the example. After you
allow measurement, array.js loads and capture requests to your API host
follow. Trigger one guarded event and check that it is sent.
With loadMode: 'always', array.js loads before a choice instead. Check that
no capture request is sent while measurement is denied, unless you chose
cookieless capture.
If you turned features off, allow measurement and filter the DevTools Network
panel by posthog. Reload the page. You should see array.js, the remote
config and capture requests, but no /flags request with featureFlags: false
and none of the modules you turned off, such as surveys.js or
dead-clicks-autocapture.js.
Test in a private window with an opt-in policy. Open DevTools Network, disable the cache and filter by the vendor's domain:
- Load the page. No request goes to the vendor before you choose.
- Click Reject, then reload. There is still no vendor request.
- Open Privacy settings and allow the helper's category. The vendor script loads without a page reload.
- 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 sets vendor to its script ID, so once you declare that vendor 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.