| name | posthog-data-handling |
| description | PostHog PII handling, GDPR compliance, consent management, data deletion,
property sanitization, and privacy-safe analytics configuration.
Trigger: "posthog data", "posthog PII", "posthog GDPR", "posthog data
retention", "posthog privacy", "posthog CCPA", "posthog consent".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","posthog","compliance"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
PostHog Data Handling
Overview
Privacy-safe analytics with PostHog. Covers property sanitization to strip PII before events leave the browser, consent-based tracking (opt-in/opt-out), GDPR data subject access requests and deletion, and PostHog's built-in privacy controls (IP masking, session recording masking).
Prerequisites
- PostHog project (Cloud or self-hosted)
posthog-js and/or posthog-node installed
- Privacy policy covering analytics data collection
- Cookie consent mechanism (e.g., CookieConsent banner)
Instructions
Step 1: Privacy-Safe Initialization
import posthog from 'posthog-js';
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
api_host: 'https://us.i.posthog.com',
autocapture: false,
respect_dnt: true,
opt_out_capturing_by_default: false,
sanitize_properties: (properties, eventName) => {
delete properties['$ip'];
delete properties['$device_id'];
if (properties['$current_url']) {
properties['$current_url'] = properties[]
.(, )
.(, )
.(, );
}
(properties[]) {
properties[] = properties[]
.(, );
}
properties;
},
: {
: ,
: ,
},
});