mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
feat(analytics): record where paying customers actually came from
Adds first-party acquisition attribution and a sixteen-event funnel, written to this deployment's own database and read back on /admin/growth. Nothing is sent anywhere else, and the whole subsystem is off unless OPENFRAME_ENABLE_ANALYTICS is set, so a self-hosted instance carries the tables empty and pays nothing. The proxy gives a visitor an anonymous id and stores what brought them in two first-party cookies; signup copies that onto the account and claims the events the visitor produced before they had one, which is what joins the two halves of the funnel. Recording happens where each step actually happens rather than in the browser: an ad blocker cannot undercount landing views, and blocking rates differ by channel, so an undercounted denominator would have made GitHub traffic look like it converts better than it does. Every event carries a dedupe key on a UNIQUE column, so "recorded exactly once" is a property of the schema rather than of fifteen call sites. Subscription events are derived by comparing the row being overwritten with the row being written inside the existing Stripe sync, which makes them order-independent and replay-safe. The scoreboard reports step-to-step conversion with the denominator beside it, and splits by source over a rolling 28-day window rather than a week: at this volume a weekly per-source cell holds single digits, and a percentage computed from three visits reads exactly as confidently as one computed from three hundred. "How did you hear about us?" is asked on the first onboarding screen, not on the registration form. The number being measured is the signup conversion rate, and a question added to that form would move it.
This commit is contained in:
@@ -98,6 +98,16 @@ export function isInviteCodeRequired() {
|
||||
return readBooleanEnv('OPENFRAME_REQUIRE_INVITE_CODE', true);
|
||||
}
|
||||
|
||||
// Acquisition attribution and funnel events. Defaults to OFF, unlike the other
|
||||
// product flags here, because the cost of the two mistakes is not symmetric: a
|
||||
// hosted instance that forgets to switch it on shows an empty growth page and is
|
||||
// noticed the same day, while a self-hosted instance that gets it silently
|
||||
// switched on accumulates rows nobody asked for. Nothing is ever sent off the
|
||||
// instance either way, so this is about cost, not disclosure.
|
||||
export function isProductAnalyticsEnabled() {
|
||||
return readBooleanEnv('OPENFRAME_ENABLE_ANALYTICS', false);
|
||||
}
|
||||
|
||||
function parseBigIntEnv(name: string, defaultValue: bigint, minValue?: bigint): bigint {
|
||||
const raw = process.env[name]?.trim();
|
||||
if (!raw) return defaultValue;
|
||||
|
||||
Reference in New Issue
Block a user