Skip to main content

Product Analytics

What the three web frontends (the dashboard, the docs site and the design system site) send to PostHog, under which consent, the event catalogue, how to add an event and what running an A/B test would take. The owner's one-time set-up in PostHog is POSTHOG_SETUP.md.


Overview​

All three sites send to one PostHog Cloud US project. Every event carries site (dashboard, docs or design), so one project tells them apart.

SiteWhere the browser sendsCode
Dashboard/ingest on its own origin; src/proxy.ts forwards it to POSTHOG_API_HOST (https://us.i.posthog.com) and the SDK's files from https://us-assets.i.posthog.comsrc/apps/github-backup-dashboard/src/lib/analytics/, src/instrumentation-client.ts
Docs sitehttps://us.i.posthog.com directly (a static site has no server to proxy)src/apps/github-backup-docs/src/analytics.ts, src/theme/Root.tsx
Design sitehttps://us.i.posthog.com directlysrc/apps/github-backup-design/src/lib/analytics.ts, src/instrumentation-client.ts

Analytics is off unless NEXT_PUBLIC_POSTHOG_KEY holds the project key when a site is built (Next.js and Docusaurus put it into the browser bundle). Off means no PostHog code runs (the SDK chunk is never fetched), no request leaves the browser and no cookie is set; the dashboard's /ingest answers 404. Development, the tests and CI run this way. No build on main sets the key today: the dashboard's Docker image is built without it, and the docs and design sites are built locally and not hosted, so analytics is off everywhere until a build passes the key.

SettingRead byDefault
NEXT_PUBLIC_POSTHOG_KEYall three sites, at build time; the dashboard's server tooempty: off
NEXT_PUBLIC_POSTHOG_HOSTthe dashboard's browser code, at build time/ingest
POSTHOG_API_HOSTthe dashboard's server: the /ingest proxy and posthog-nodehttps://us.i.posthog.com

Ahrefs Web Analytics (dashboard only)​

The dashboard's public pages also load Ahrefs Web Analytics (https://analytics.ahrefs.com/analytics.js, with the project's public site key from the server setting AHREFS_SITE_KEY; unset, Ahrefs is not loaded), for page view counts next to Ahrefs' SEO tools. It runs under the same choice as PostHog: src/components/analytics/AhrefsAnalytics.tsx, mounted only in the marketing layout, adds the script only while the choice is granted and adds it when the visitor turns analytics on; Global Privacy Control and Turn off analytics keep it from loading (a script that already ran stays until the next page load). It loads only on the public site's host (getAhrefsHost() in src/config/analytics-env.ts), so local servers, CI (including the Lighthouse job) and other installs never send their visits to the site's Ahrefs project; NEXT_PUBLIC_AHREFS_HOST, inlined at build time, names another host, which only the browser tests use. tests/e2e/specs/analytics.spec.ts checks that it loads once on /, never on /signin, never with Global Privacy Control, and not again after Turn off analytics and a reload. It is not loaded behind sign-in because Ahrefs keeps full URLs with their query strings. Per Ahrefs' help centre it sets no cookie, discards the IP address after deriving a city-level location, and stores page URLs, the user agent and the screen size. Because every build loads it, the dashboard's Analytics settings button and panel exist even without a PostHog key. The Privacy Policy lists Ahrefs as a processor (owner decision 2026-11-05: keep it, behind the choice).

Analytics is on by default and off for visitors who turn it off or whose browser sends Global Privacy Control. The owner chose this on 2026-11-04: an opt-in panel meant most visits were never counted. Visitors from the EU and the UK need opt-in for analytics cookies and session replay, so go back to an opt-in panel before the sites aim at them.

  • First visit. Nothing asks. posthog-js loads (a separate chunk) and starts capturing, unless the browser sends Global Privacy Control (navigator.globalPrivacyControl in the browser, the Sec-GPC: 1 header on the dashboard's server), which some US states treat as a legal opt-out. Then nothing is sent and no PostHog cookie is set.
  • Analytics settings in the footer of every public dashboard page, in the dashboard's Privacy Policy (/privacy#analytics), and in the footers of the docs and design sites opens a small panel. It says whether analytics is on and has one button, Turn off analytics or Turn on analytics. The panel links to the analytics privacy notice. On the dashboard the panel is a chunk of its own (ConsentPanel.tsx), fetched when the pointer or keyboard focus first reaches the button; AnalyticsConsent.tsx in the root layout listens for the button and for Escape. If the chunk does not load (offline, or a tab opened before a redeploy), the panel says the settings did not load and offers Reload the page.
  • The choice is a first-party cookie, ghb_analytics_consent=granted|denied (180 days, SameSite=Lax, Secure on HTTPS), written only when the visitor uses the button. It is set on the widest domain the browser accepts (a probe cookie finds it; browsers refuse public suffixes), so sites under one parent domain share one choice. A choice stored before 2026-11-04 on a single host is cleared when the visitor next chooses. The dashboard's server reads it before it sends a server-side event.
  • On. posthog-js starts with opt_out_capturing_by_default and opt_out_persistence_by_default and is opted in at once; from then on it keeps its identity in the ph_<key>_posthog cookie and local storage, per site.
  • Off, at any time: opt_out_capturing() stops capturing and, with opt_out_persistence_by_default, deletes PostHog's cookie and local storage; session recording stops. The next page load does not start PostHog.

The code for this is effectiveConsent() in the dashboard's src/lib/analytics/consent.ts (a stored choice wins; with none, on unless Global Privacy Control) and the getConsent() copies in src/apps/github-backup-docs/src/analytics.ts and src/apps/github-backup-design/src/lib/analytics.ts.

What is captured​

On the dashboard, src/instrumentation-client.ts starts analytics once the browser is idle after the first render (requestIdleCallback, at most 4 s; setTimeout 1.5 s where it is missing), so posthog-js never competes with the page's own scripts; the first page view is captured then. posthog-js and its init options with the privacy rules (posthog-config.ts, privacy.ts) load together at that point, so a page where analytics never starts downloads neither. Catalogue events tracked before that (for example preorder_viewed for a visitor who lands on /#preorder) are held in the page, at most 20, and sent once posthog-js has loaded; turning analytics off drops them. While analytics is on, posthog-js (defaults: "2026-08-30", person_profiles: "identified_only") records:

  • page views on every client-side navigation (capture_pageview: "history_change") and page leaves;
  • autocaptured clicks and form submissions, dead clicks and rage clicks;
  • web vitals (LCP, CLS, FCP, INP);
  • heatmaps and session replays (replays sampled in the project's settings), except when the SDK starts on one of the dashboard's marketing pages (/, /pricing, /about, /contact, /terms, /privacy, /refund; isMarketingPath() in privacy.ts, buildPosthogConfig() in posthog-config.ts): there it starts with disable_session_recording and without heatmaps, and keeps them off for the rest of that page load;
  • the custom events of the catalogue below.

The privacy rules are in code and tested (src/lib/analytics/privacy.ts, privacy.test.ts):

RuleHow
Every input is masked in replays, on every sitesession_recording.maskAllInputs
Pages that show an account's data are masked: every page except /, /pricing, /terms, /privacy, /refund, /about, /contact and /signin (/delivery only redirects to /refund#delivery). A page added later is masked until it is listed.replay: maskTextSelector: "*" with maskTextFn, which masks all text there; autocapture: before_send drops the clicked element's text, link and attribute values ($el_text, $elements_chain, $elements, $external_click_url)
Nothing from /api/* or /ingest/*before_send drops such events; replay's network log leaves such requests out (maskCapturedNetworkRequestFn); request headers and bodies are never recorded
URLs lose their query string except utm_*every *url and *referrer property, $set_once, heatmap batches and replay network entries; a link code (/link?code=), an OAuth state or a return path never leaves the browser
The person is the account id, nothing elseidentify(String(accountId)) after sign-in (the session reports accountId), no person properties; reset() on sign-out and account deletion
No cookie reaches PostHog through the proxysrc/lib/analytics/ingest-proxy.ts forwards an allowlist of headers (content type and encoding, user agent, X-Forwarded-For for the location, Origin); never Cookie, Authorization or Referer

PostHog's own events are therefore $pageview, $pageleave, $autocapture, $rageclick, $dead_click, $web_vitals, heatmap batches, $snapshot (replays), and $identify.

Why the proxy is in src/proxy.ts​

PostHog's Next.js guide proxies with rewrites in next.config.ts. A rewrite forwards the browser's cookies, the httpOnly session among them, to PostHog. src/proxy.ts therefore handles /ingest/* itself, before the login gate: it rewrites /ingest/static/* and /ingest/array/* to the assets host and the rest to POSTHOG_API_HOST with the allowlisted headers only (NextResponse.rewrite with request.headers). next.config.ts sets skipTrailingSlashRedirect because PostHog's paths end in a slash (/ingest/e/); src/proxy.ts redirects every other /path/ to /path as Next.js would. Replays are the largest part of that traffic.

Server side​

posthog-node (src/lib/analytics/server.ts) sends events that only the server sees, only with the key and the granted cookie: captureServer() sends one and flushes it (bounded at 3 s). A route handler schedules it with after() so the response does not wait: today the GitHub sign-in's sign_in_completed, with the account id as the distinct id. The server evaluates no feature flags.

Event catalogue​

Defined in src/apps/github-backup-dashboard/src/lib/analytics/events.ts; events.test.ts fails when an event is missing here. Every event also carries site. No property holds personal data: no email address, GitHub login, repository or token name, or message text.

EventWhenPropertiesSent from
landing_cta_clickedA call to action on a public page is clickedcta: nav_primary (the nav's button; it led to the pre-order section until 2026-11-05 and to /pricing since), hero_primary (the hero's filled button; until 2026-11-05 it was "Open Dashboard" to /dashboard, so a trend across that date mixes the two; since 2026-11-06 it is "Pricing and FAQ" to /pricing, the same place as nav_primary, and is there only when the build offers no pre-order action, because the hero shows the waitlist form or the pay buttons in its place, which send waitlist_joined and preorder_clicked), preorder_pricing (the home page's price band's link to /pricing), pricing_how (the /pricing plan card's link to /#how while pre-orders and the waitlist are both closed). Retired on 2026-11-08 when the docs site stopped being hosted: nav_docs, hero_docs, pricing_docs. Retired on 2026-11-06 with the home page's closing card: closing_primary. Retired on 2026-11-05 with the links or the section they marked, so older events still carry them: nav_open_app, nav_github, hero_github, source_github, source_docs, closing_open_dashboard, closing_github, and preorder_docs (the pre-order section's documentation link, gone when the section became a price band that links to /pricing)links marked with ctaAttributes(); AnalyticsClickTracker in the marketing layout
preorder_viewedA quarter of the home page's price band (#preorder) is visible, once per page viewpreorders_openPreorderViewTracker
preorder_clickedA pre-order payment link is opened, on /pricing or in the home page's hero (since 2026-11-06; in the price band before), so the page's path says which: the home page shows its pay buttons once, in the hero, and the price band links to /pricing; plan_selected and checkout_started followcurrency: inr, usdlinks marked with preorderAttributes()
waitlist_joinedThe waitlist accepted an address (the address is not sent)preorders_openWaitlistForm: in the home page's hero since 2026-11-06 (in the price band before, so a funnel from preorder_viewed to it changes meaning on that date) and on the /pricing plan card
sign_in_started"Sign in with GitHub" is clicked or the password form is sentmethod: github, passwordLoginPanel
sign_in_completedA session was createdmethoduseAuth (password); the GitHub callback route, server side
agent_linkedA worker's link code is approved on /linknoneLinkAgentForm
first_backup_seenThe overview shows backup runs, the first time for this person on this browsertotal_runsFirstBackupTracker on /dashboard
ai_message_sentA question is sent to the AI assistant (its text is not sent)new_conversation, model (default when none is chosen)AIDashboard
plan_selectedA plan and currency are chosen: the currency buttons on /pricing (a click that changes the currency, not the automatic guess), or a pre-order payment linkplan (founding for the pre-order), billing_period (monthly, yearly), currencyCurrencyScope; AnalyticsClickTracker for the payment links; the billing UI, when it exists
checkout_startedThe payment step opens: a pre-order payment link (Razorpay's page)the same, and amount_minor (the amount in the currency's minor unit: 199900 paise or 3600 cents for the founding plan)AnalyticsClickTracker; the billing UI, when it exists
checkout_completedBilling, not sent yet: the provider confirmed the paymentthe same as checkout_startedthe billing UI, or the payment webhook through captureServer()
checkout_failedBilling, not sent yet: the payment failed or was cancelledplan, billing_period, currency, reason (the provider's error code)the billing UI

The docs and design sites send no custom events: page views, clicks, heatmaps, web vitals and replays only.

Adding an event​

  1. Add it to AnalyticsEventProperties in events.ts with the type of its properties, and to EVENT_NAMES there (the compiler fails until both agree). Names are object_verb in snake case.
  2. Send it. In client code, track("event_name", { ... }); it does nothing without the key or while analytics is off, so the caller never checks. For a "first time" event, trackOnce(). For a link rendered by a server component, add a data attribute helper like ctaAttributes() in attributes.ts instead of a client component. In a route handler: if (canCaptureServer(request.cookies)) after(() => captureServer({ consent, distinctId, event }, properties)), with the account id as distinctId.
  3. Add a row to the catalogue above (events.test.ts checks it) and a test for the new call where the component has one.
  4. Keep personal data out: ids and counts, not names, addresses or text.

Experiments​

No experiment runs in the code. The landing hero's landing-hero-cta experiment was removed on 2026-11-05 while it was still a draft with an inactive flag: both of its labels led to the dashboard, and the marketing pages became static pages that read no cookies, so a flag evaluated per request on the server no longer fits them. The draft experiment and its flag are still in PostHog; end or archive them there. The removed code (an EXPERIMENTS registry, useExperiment, FlagBootstrapProvider and getFlagBootstrap(), which read the visitor's distinct id from the ph_<key>_posthog cookie and evaluated the flag with posthog-node) is in the history before that change.

To run one on a static page, read the variant in the browser once posthog-js has loaded (getFeatureFlag(key), which also records the $feature_flag_called exposure); the first paint shows the control, so put the variant below the fold or accept one change of label. In PostHog:

  1. Experiments → New experiment: the hypothesis, and the feature flag key exactly as the code reads it.
  2. Variant rollout: control and test, 50/50, rollout 100%. Participant type: users.
  3. Analytics: exposure is the default $feature_flag_called; exclude people exposed to both variants; turn on filter test accounts once your own accounts are marked as test accounts.
  4. Metrics: a funnel from the exposure to the event the change should move (for example landing_cta_clicked with one cta), and the events after it as secondary metrics.
  5. Save as draft, check the flag's variants on its page, then Launch. Let it run at least the duration the experiment page recommends and at least a full week; act on a result when the credible interval for the primary metric excludes zero. Then ship the winner as the only version, remove the flag read from the code, deploy, and end the experiment and archive its flag.

Tests​

cd src/apps/github-backup-dashboard && pnpm test covers the wrapper (no call without a key or consent, typed calls with them, identify and reset), consent (the cookie, the choice during a visit), the privacy rules, the /ingest proxy and its place before the login gate, the trailing-slash redirect, server-side capture and the GitHub sign-in event. The dashboard sends no Content-Security-Policy; its PostHog traffic is same-origin.

make e2e (tests/e2e, Playwright; see its README.md) checks the consent rules in a browser, on production builds of all three sites with a fake key (phc_e2etest): a first visit shows no panel and sends a $pageview with the right site; Analytics settings says analytics is on; Turn off analytics deletes the ph_ cookies, nothing captured after it is sent, and the next page load sends nothing; Turn on analytics starts it again; Global Privacy Control sends nothing and the panel says off; analytics turned off on the design site is off on the docs site (the docs and design builds run as docs.ghb.test and design.ghb.test, so the consent cookie is shared through the parent domain). Every request to PostHog is answered inside the browser, so no test reaches it. CI runs it on every change to a frontend (Frontend E2E (Playwright)).

To try it locally, build or run a site with a key (NEXT_PUBLIC_POSTHOG_KEY=phc_... pnpm dev) and add ?__posthog_debug=true to a URL to see posthog-js's log in the console.