368 words, 14 clausesno date on the pageread 25/09/2026source
·It's not mentioned nowhere that we should ask for consent. This has to be done, right? Is there any recommended way/example you have for it?
·Originally posted on posthog.com/docs/libraries/react
·This is clearly outlined in the docs. https://posthog.com/docs/privacy/gdpr-compliance
·Assuming your users are EU citizens you must comply with GDPR and determine whether the data processing is lawful under Article 6(1). Failing to do so can have severe consequences.
·Posthog has an excellent API for GDPR compliance. Here is how our time has handled consent within a reducer called from a Cookie banner:
·export const reducer = (state: Consent, action: Action): Consent => { switch (action.type) { case "GIVE_CONSENT": posthog.identify(action.payload.user.id.toString()) posthog.opt_in_capturing() posthog.startSessionRecording() localStorage.setItem("cookieConsent", "true") return { isVisible: false, consentGiven: true }
·What is the posthog variable here? I haven't been able to figure out how to achieve with react
·Hooks can only be called inside hooks or in a functional component. In this case the reducer is neither a hook nor a .tsx component. You can reference the posthog instance directly from: import posthog from "posthog-js"
·If you are inside a hook or a JSX/TSX component use instead:
·import { usePostHog } from "posthog-js/react"