c15t
/
C15T Logo
Frameworks
Welcome to c15t Docs
Introduction to Consent Management (c15t)
AI Tools Integrations
OSS
Contributing to c15t.com
License
Building Privacy Tools in the Open
Legal
Cookie Policy
Privacy Policy
C15T Logo
HomeFrontendIntegrationsSelf HostChangelog
xbskydiscordgithub1.4k
c15t
/
C15T Logo
Frameworks
Welcome to c15t Docs
Introduction to Consent Management (c15t)
AI Tools Integrations
OSS
Contributing to c15t.com
License
Building Privacy Tools in the Open
Legal
Cookie Policy
Privacy Policy
home-2Docs
chevron-rightIntegrations
chevron-rightPosthog

PostHog

PostHog is an open-source product analytics platform for tracking user behavior, session replays, feature flags, and A/B testing. It supports cookieless tracking, allowing analytics to continue even without cookie consent.

PostHog is an open-source product analytics platform that helps you understand user behavior, track events, and analyze product usage. Unlike traditional analytics tools, PostHog supports both cookieless and cookie-based tracking. This means you can sync c15t with PostHog and continue collecting analytics even when users haven't given consent—PostHog simply operates in cookieless mode until consent is granted.

PostHog SDK Implementation

This is the recommended approach if you're using the Posthog JS SDK, this is commonly used in React projects.

Adding the PostHog SDK to c15t

Initialize Posthog

When you initialize posthog make sure to set cookieless_mode to on_reject.

posthog.init("phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", {
  api_host: "https://eu.i.posthog.com",
  defaults: "2025-05-24",
  cookieless_mode: 'on_reject'
})

posthog.has_opted_out_capturing() // Avoids accidental tracking without consent till c15t has loaded

Adding the script to c15t

import { configureConsentManager } from 'c15t';
import { posthog } from 'posthog-js';

configureConsentManager({
  // ... 
  callbacks: {
    onConsentSet({ preferences }) {
      if (preferences.measurement) {
        posthog.opt_in_capturing();
      } else {
        posthog.opt_out_capturing();
      }
    }
  }
});

PostHog Script Implementation

If you want to load posthog via a script tag it's recommended to use this approach.

By default c15t will always load the script regardless of consent. This is because the script has built-in functionality to opt into and out of tracking based on consent.

Initialize Posthog

This script does not load the Posthog script, it only syncs the consent state with Posthog via the Posthog JS SDK.

This is due to Posthog's use of cookieless tracking. However, you need to set cookieless_mode to on_reject when initializing Posthog.

posthog.init("phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", {
  api_host: "https://eu.i.posthog.com",
  defaults: "2025-05-24",
  // PostHog will not set any cookies until the user has given consent
  cookieless_mode: 'on_reject'
})

Adding the script to c15t

import { configureConsentManager } from 'c15t';
import { posthog } from '@c15t/scripts/posthog';

configureConsentManager({
  // ... 
  scripts: [
    posthog({ 
      id: 'phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
      apiHost: 'https://eu.i.posthog.com',
      defaults: '2025-05-24', 
      options: { person_profiles: 'identified_only' }
    }),
   ],
});

Types

PosthogConsentOptions

Property
Types

Script

Property
Types
C15T Logo
Leverage native React components for seamless integration and high performance in a robust Consent Management solution that empowers your development team while prioritizing privacy and compliance.
Product
  • Documentation
  • Components
Company
  • GitHub
  • Contact
Legal
  • Privacy Policy
  • Cookie Policy
c15t