Skip to content

PostHog revamp, Stripe fixes, unified site header - #16

Merged
maxjneto merged 10 commits into
developfrom
fix/posthog-stripe
Nov 5, 2026
Merged

maxjneto merged 10 commits into
developfrom
fix/posthog-stripe

Conversation

@maxjneto

@maxjneto maxjneto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Summary

PostHog revamp

  • One analytics module (src/analytics): opt-out until cookie consent, the choice re-applied on every visit, pageviews on route changes, heatmaps, web vitals, exception capture.
  • Document text never recorded: the layout pages' iframes are masked (data-ph-mask on the srcDoc body), titles, names and comments masked or blocked; public links never recorded and their token scrubbed from URLs.
  • New event taxonomy (object_action, document_id/document_mode on everything), catalogue in docs/architecture/analytics.md.
  • Server events follow the account's cookie choice (users.analytics_consent, migration 004): accepted → Clerk id; declined or never answered → anonymous anon_<HMAC> with no person profile.
  • /ingest proxy blocks for Caddy, APP_VERSION/VITE_APP_VERSION in builds, error tracking in the API middleware, toolset on MCP tool-call telemetry.

Stripe

  • Stripe calls off the event loop; no second subscription (local check + asks Stripe, healing the plan if a webhook was lost); an unknown price on an active subscription keeps Pro; Stripe refusals become 502.
  • The week's allowance follows the plan change; subscribers see "Manage" instead of "Get Pro".
  • Billing page waits for the webhook after checkout.

Site

  • One SiteHeader everywhere, footer on every screen but the editor, privacy/terms/contact in one shell with pt-BR texts.

Other

  • /marketing/ kit out of git; preview write hook kept.

Deploy notes

  • Migration 004 runs on start (backup first).
  • VPS .env: POSTHOG_ENABLED, POSTHOG_API_KEY, POSTHOG_ANON_SALT (never changes), Stripe vars.
  • Caddy needs the /ingest block before this frontend ships (VITE_POSTHOG_HOST=https://doc-forge.dev/ingest).

Test plan

  • Backend 169, frontend 111, MCP 23 tests; ruff, tsc, vite build
  • Stripe test mode end to end locally (checkout, webhook, portal, duplicate guard)
  • PostHog locally: events, identify, replay masking, consent on return visit

…captures write through

marketing/ (capture, compositor, renders) stays local and is ignored. __previewWrite only exists in the preview build (npm run dev:preview).
…e, Stripe calls off the event loop

- checkout refuses people who already subscribe (409, manage it in the portal)
- an active subscription on a price we don't know grants Pro instead of Free
- Stripe SDK calls run in the threadpool
- billing page asks for the plan again after checkout until the webhook lands
…, flush on shutdown

- consent from an earlier visit counts, so identify runs after a reload
- capture_pageview: history_change for the SPA
- backend PostHog client flushes its queue when the app stops
…ents by object and action

Privacy (the policy promised it, the layout editor did not do it):
- layout pages render in same-origin iframes: maskForRecording() puts data-ph-mask
  on their <body>, so rrweb masks the text and blocks the images inside
- slide thumbnails (SVG data URIs holding the slide's text) are blocked
- side panels, titles, presence, comments and in-place editing are masked;
  names that sit in attributes are ph-no-capture; autocapture skips content areas
- public-link tokens are scrubbed from every URL property; public pages never record

Foundation: src/analytics (init, track with document context, consent, identity),
environment/app_version/locale on every event, nothing sent from localhost unless
VITE_POSTHOG_DEV=1, heatmaps, web vitals and exception capture after consent. The
cookie choice is also sent to the account so server events can follow it.

Events: the server now records what used to be duplicated here (document created,
reviews, versions, comments, themes); "Reviewed" goes to the backend. New: style,
looks, header/footer, shortcuts, undo/redo, collaboration, marketing CTAs, snippets
and the demo.
…, error tracking

- users.analytics_consent (migration 004) set by PATCH /users/me from the banner
- accepted: the Clerk id and $set (plan); declined or never answered: a stable
  anon_<HMAC> pseudonym with no person profile (POSTHOG_ANON_SALT)
- events renamed to object_action with `source` (agent | person) and
  `document_mode`: document_created (one event for Markdown, layout, app and MCP),
  agent_changes_reviewed (north star, new POST /layout/reviewed), version_*,
  comment_*, document_shared/moved/published/exported, folder_created,
  checkout_started, subscription_started/canceled
- mcp_api_request only on failure (agent_request_failed); render_page counted once
- unhandled errors go to PostHog error tracking, never tied to a person
- MCP tool calls report their toolset
- funnel script on the new server-only events, production only
…alogue

- Caddy: /ingest -> PostHog, so blockers don't drop a developer audience
  (validated with caddy:2-alpine)
- VITE_APP_VERSION / APP_VERSION from the git SHA; VITE_POSTHOG_UI_HOST
- docs/architecture/analytics.md: sources, consent and identity, what is never
  sent, the event catalogue and configuration
…ripe refuses

- the "already subscribed" check relied on the local plan, which only changes when
  the webhook lands; a late or lost webhook let a second payment open a second
  subscription. Checkout now lists the customer's subscriptions in Stripe first,
  refuses with 409 and heals the plan if one is still paid for
- Stripe errors on checkout and portal (e.g. a restricted key without Customer
  Portal: Write) are logged with Stripe's message and answered with a clear 502
…sent to manage, not to pay again

- on a plan change the remaining document creations move by the difference
  between the allowances (free → Pro: 15 left becomes 100 left; what was used
  still counts; back to free never goes negative). Before, a new subscriber kept
  the free 15 out of 100 until Sunday's reset
- the pricing page knows the signed-in plan: a subscriber sees "Your plan ·
  Manage" (to /billing) instead of "Get Pro"; a 409 from checkout goes to
  /billing instead of a generic error
The banner only calls setConsent when there is no choice yet, so someone who
accepted on an earlier visit stayed opted out of PostHog for good.
…ditor, legal pages in Portuguese

SiteHeader replaces MarketingNav and TopBar: the links depend only on being
signed in or not. Privacy, terms and contact share one shell, with pt-BR texts
next to the English ones.
@maxjneto
maxjneto merged commit 3547842 into develop Nov 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant