mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
fix(analytics): remove PostHog consent banner and opt-out gating for private beta (#23333)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Paperclip Cloud sends browser product analytics and session replays to PostHog when enabled for a hosted stack (self-hosted installs never load posthog-js) > - Previously, an EU/UK/Swiss consent banner and Profile settings opt-out toggle gated browser analytics and dropped metrics when visitors did not opt in > - During private beta, we want to stop showing the consent banner and opt-out prompt anywhere while continuing to send metrics (compliance will be handled separately later) > - This pull request removes the consent banner, Profile opt-out toggle, and client-side consent gating across the UI and sets `consentRequired: false` on the server response > - The benefit is zero banner friction during private beta and uninterrupted PostHog product metrics, while keeping all replay/autocapture privacy masking and pre-load event queuing intact ## Linked Issues or Issue Description **What existing behavior does this improve?** Paperclip Cloud browser product analytics initialization (`ProductAnalyticsGate`, `ui/src/lib/analytics`, `ProfileSettings`, `cloud-posthog-browser.ts`). **Subsystem affected** Cross-cutting (multiple of the above) — `ui/` and `server/`. **Current behavior** In EU/EEA/UK/Swiss regions (or unknown time zones), `ProductAnalyticsGate` renders `AnalyticsConsentBanner` and blocks loading `posthog-js` until the visitor clicks Accept. `ProfileSettings` also renders a `ProductAnalyticsSetting` opt-out switch. **Proposed behavior** Remove `AnalyticsConsentBanner`, `ProductAnalyticsSetting`, and client-side consent gating so `ProductAnalyticsGate` loads PostHog unconditionally when `browserAnalytics` is enabled for a Cloud stack. Return `consentRequired: false` from `resolveBrowserAnalyticsConfig` so cached older UI bundles also stop prompting during rollout, and keep `opt_in_capturing()` when `has_opted_out_capturing()` is true so previously opted-out browsers resume sending metrics. **Reason and benefit** During private beta, the EU/UK consent banner adds friction and drops PostHog product metrics. Removing the banner and opt-out gating restores full metric delivery while keeping all replay/autocapture privacy masking and pre-load event queuing intact. **Breaking changes** None — `browserAnalytics.consentRequired` remains on the session payload (as `false`), self-hosted installs still receive `browserAnalytics: null`, and per-stack env controls (`PAPERCLIP_POSTHOG_BROWSER_ENABLED`, `PAPERCLIP_POSTHOG_REPLAY_ENABLED=0`) continue to work. ## What Changed - Deleted `ui/src/components/AnalyticsConsentBanner.tsx`, `ui/src/components/ProductAnalyticsSetting.tsx`, `ui/src/lib/analytics/consent.ts`, and their unit tests. - Simplified `ui/src/components/ProductAnalyticsGate.tsx` to start PostHog unconditionally after the page settles and render `null`. - Simplified `ui/src/lib/analytics/product-analytics.ts` to remove consent-state gating while keeping pre-load event queuing (`MAX_QUEUED_PRODUCT_EVENTS`) and automatic opt-in for browsers with a prior PostHog opt-out. - Removed `ProductAnalyticsSetting` from `ui/src/pages/ProfileSettings.tsx` and its mock in `ui/src/pages/mobile-collections-responsive.test.tsx`. - Updated `server/src/services/cloud-posthog-browser.ts` to always return `consentRequired: false`. - Updated `ui/src/components/ProductAnalyticsGate.test.tsx`, `ui/src/lib/analytics/onboarding-analytics.test.tsx`, `server/src/__tests__/cloud-posthog-browser.test.ts`, `server/src/__tests__/auth-routes.test.ts`, and `doc/cloud-browser-analytics.md`. ## Verification - `pnpm vitest run ui/src/components/ProductAnalyticsGate.test.tsx ui/src/lib/analytics/onboarding-analytics.test.tsx ui/src/lib/analytics/product-analytics.test.ts ui/src/pages/mobile-collections-responsive.test.tsx server/src/__tests__/cloud-posthog-browser.test.ts server/src/__tests__/auth-routes.test.ts` — all passed. - `pnpm --filter @paperclipai/ui typecheck` — passed. - `pnpm --filter @paperclipai/server typecheck` — passed. ## Risks - Low risk: self-hosted installs remain unaffected (`browserAnalytics` is still `null`). All replay/autocapture privacy masking and `/_ph` proxy allowlists remain unchanged. Per-stack opt-out (`PAPERCLIP_POSTHOG_BROWSER_ENABLED` / `PAPERCLIP_POSTHOG_REPLAY_ENABLED=0`) continues to work. ## Model Used - Google Gemini (Antigravity agent with tool use and code execution) ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
adc4501689
commit
1eae356c55
16 files changed
+77
-849
No files matched your search
@@ -131,13 +131,13 @@ describe("auth routes", () => {
|
||||
environment: "staging",
|
||||
stackId: "stack-1",
|
||||
replayEnabled: true,
|
||||
consentRequired: null,
|
||||
consentRequired: false,
|
||||
cloudTrialInferenceEnabled: false,
|
||||
});
|
||||
|
||||
vi.stubEnv("PAPERCLIP_POSTHOG_COUNTRY_HEADER", "cf-ipcountry");
|
||||
const eu = await request(createApp(actor, baseUser)).get("/api/auth/get-session").set("CF-IPCountry", "FR");
|
||||
expect(eu.body.browserAnalytics.consentRequired).toBe(true);
|
||||
expect(eu.body.browserAnalytics.consentRequired).toBe(false);
|
||||
const us = await request(createApp(actor, baseUser)).get("/api/auth/get-session").set("CF-IPCountry", "US");
|
||||
expect(us.body.browserAnalytics.consentRequired).toBe(false);
|
||||
});
|
||||
|
||||
@@ -49,23 +49,20 @@ describe("browser analytics config exposure", () => {
|
||||
environment: "production",
|
||||
stackId: "stack-1",
|
||||
replayEnabled,
|
||||
consentRequired: null,
|
||||
consentRequired: false,
|
||||
cloudTrialInferenceEnabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("decides consent from the configured edge country header, and leaves it to the browser otherwise", () => {
|
||||
it("never requires consent regardless of edge country headers", () => {
|
||||
const on = { ...CLOUD, ...TOKEN, ...BROWSER };
|
||||
const withHeader = { ...on, PAPERCLIP_POSTHOG_COUNTRY_HEADER: "CF-IPCountry" };
|
||||
expect(resolveBrowserAnalyticsConfig(on, { "cf-ipcountry": "DE" })?.consentRequired).toBeNull();
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "DE" })?.consentRequired).toBe(true);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "gb" })?.consentRequired).toBe(true);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "CH" })?.consentRequired).toBe(true);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "NO" })?.consentRequired).toBe(true);
|
||||
expect(resolveBrowserAnalyticsConfig(on, { "cf-ipcountry": "DE" })?.consentRequired).toBe(false);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "DE" })?.consentRequired).toBe(false);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "gb" })?.consentRequired).toBe(false);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "CH" })?.consentRequired).toBe(false);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "US" })?.consentRequired).toBe(false);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": "XX" })?.consentRequired).toBeNull();
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, {})?.consentRequired).toBeNull();
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, { "cf-ipcountry": ["FR", "US"] })?.consentRequired).toBe(true);
|
||||
expect(resolveBrowserAnalyticsConfig(withHeader, {})?.consentRequired).toBe(false);
|
||||
});
|
||||
|
||||
it("always sends an environment: the explicit variable, else staging or production from the host", () => {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// The browser sends to `POSTHOG_PROXY_PATH` on its own origin, not to PostHog,
|
||||
// so ad blockers do not drop the events. See `routes/posthog-proxy.ts`.
|
||||
|
||||
import { countryRequiresAnalyticsConsent, type BrowserAnalyticsConfig } from "@paperclipai/shared";
|
||||
import type { BrowserAnalyticsConfig } from "@paperclipai/shared";
|
||||
import { isCloudStagingInstance, type CloudInstanceEnv } from "./cloud-instance.js";
|
||||
import { resolveCloudPostHogConfig, type CloudPostHogConfig } from "./cloud-posthog-config.js";
|
||||
|
||||
@@ -20,13 +20,6 @@ const POSTHOG_CLOUD_INGEST_HOST = /^(us|eu)\.i\.posthog\.com$/i;
|
||||
|
||||
export type RequestHeaders = Record<string, string | string[] | undefined>;
|
||||
|
||||
export function resolveAnalyticsConsentRequired(env: CloudInstanceEnv, headers: RequestHeaders): boolean | null {
|
||||
const headerName = env.PAPERCLIP_POSTHOG_COUNTRY_HEADER?.trim().toLowerCase();
|
||||
if (!headerName) return null;
|
||||
const value = headers[headerName];
|
||||
return countryRequiresAnalyticsConsent(Array.isArray(value) ? value[0] : value);
|
||||
}
|
||||
|
||||
/** The browser analytics part of the Cloud PostHog config, or null when it is off. */
|
||||
export function resolveBrowserPostHogConfig(env: CloudInstanceEnv = process.env): CloudPostHogConfig | null {
|
||||
const config = resolveCloudPostHogConfig(env);
|
||||
@@ -53,7 +46,7 @@ export function posthogUiHost(ingestHost: string): string | null {
|
||||
|
||||
export function resolveBrowserAnalyticsConfig(
|
||||
env: CloudInstanceEnv = process.env,
|
||||
headers: RequestHeaders = {},
|
||||
_headers: RequestHeaders = {},
|
||||
options?: { cloudTrialInferenceEnabled?: boolean },
|
||||
): BrowserAnalyticsConfig | null {
|
||||
const config = resolveBrowserPostHogConfig(env);
|
||||
@@ -74,7 +67,9 @@ export function resolveBrowserAnalyticsConfig(
|
||||
environment: config.environment ?? (isCloudStagingInstance(env) ? "staging" : "production"),
|
||||
stackId: config.stackId,
|
||||
replayEnabled: config.replayEnabled,
|
||||
consentRequired: resolveAnalyticsConsentRequired(env, headers),
|
||||
// Consent banner is disabled during private beta; sending false also keeps
|
||||
// any cached older UI bundle from prompting during rollout.
|
||||
consentRequired: false,
|
||||
cloudTrialInferenceEnabled:
|
||||
typeof options?.cloudTrialInferenceEnabled === "boolean"
|
||||
? options.cloudTrialInferenceEnabled
|
||||
|
||||
Reference in new issue
Block a user