mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
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.
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { conversionRates } from '@/lib/analytics/scoreboard';
|
|
|
|
const WEEK = {
|
|
visitors: 200,
|
|
signups: 20,
|
|
firstVideo: 10,
|
|
shareLinks: 5,
|
|
externalFeedback: 1,
|
|
trials: 4,
|
|
newPaid: 1,
|
|
};
|
|
|
|
describe('conversionRates', () => {
|
|
it('divides each step by the one above it', () => {
|
|
const rates = conversionRates(WEEK);
|
|
expect(rates.visitorToSignup).toBeCloseTo(0.1);
|
|
expect(rates.signupToFirstVideo).toBeCloseTo(0.5);
|
|
expect(rates.firstVideoToShare).toBeCloseTo(0.5);
|
|
expect(rates.shareToFeedback).toBeCloseTo(0.2);
|
|
expect(rates.trialToPaid).toBeCloseTo(0.25);
|
|
});
|
|
|
|
it('returns null rather than zero when the denominator is zero', () => {
|
|
const rates = conversionRates({ ...WEEK, visitors: 0, trials: 0 });
|
|
expect(rates.visitorToSignup).toBeNull();
|
|
expect(rates.trialToPaid).toBeNull();
|
|
// "nobody arrived" and "nobody converted" are different facts, and the rest
|
|
// of the funnel still has to report normally.
|
|
expect(rates.signupToFirstVideo).toBeCloseTo(0.5);
|
|
});
|
|
|
|
it('reports a step where nobody converted as zero, not as missing', () => {
|
|
expect(conversionRates({ ...WEEK, newPaid: 0 }).trialToPaid).toBe(0);
|
|
});
|
|
});
|