Repository navigation
fix(analytics): skip PostHog when the browser sends DNT or GPC - #144
Conversation
posthog-js is_capturing() returns true under cookieless_mode always before it checks respect_dnt, so DNT and GPC visitors were still tracked. Skip posthog.init, the error listeners and pageviews when the browser opts out, and drop events in before_send as a second guard.
|
No actionable comments were generated in the recent review. WalkthroughThe frontend now detects browser DNT and GPC signals and uses them to control PostHog initialization, event submission, and router-transition pageviews. Signal reads tolerate malformed inputs and throwing getters. Tests cover recognized signals, invalid values, and tracking guards. ChangesPostHog privacy opt-out
Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Browser
participant Instrumentation as instrumentation-client.ts
participant Privacy as browserRequestsNoTracking
participant PostHog
Browser->>Instrumentation: provide navigator and window
Instrumentation->>Privacy: check privacy signals
Privacy-->>Instrumentation: return opt-out status
Instrumentation->>PostHog: initialize when configured and opted in
Instrumentation->>PostHog: capture router-transition pageview when opted in
PostHog->>Privacy: recheck signals in before_send
Privacy-->>PostHog: return opt-out status
Possibly related PRs
Suggested reviewers: Merge Risk:
|
|
@coderabbitai review |
Action performed
|
Visitors who send Do Not Track or Global Privacy Control were still being tracked. In posthog-js 1.447.2,
is_capturing()returns true undercookieless_mode: "always"before the consent check runs, sorespect_dntnever kicks in.browserRequestsNoTrackinginlib/posthog-privacy.tsreadsnavigator.doNotTrack,msDoNotTrack,window.doNotTrackandnavigator.globalPrivacyControl. When any of them is set,instrumentation-client.tsskipsposthog.init, the error listeners and every pageview, andbefore_senddrops the event as a second check.respect_dnt: truestays in the config.Unit tests cover each signal, the negatives and throwing getters, and a source contract keeps init and
before_sendbehind the guard. Locally, check, test:posthog (37/37), build, test:posthog:browser and Qlty all pass.Summary by CodeRabbit