From 99e113130d1acc9ee77c77dadd2667b65a0476b9 Mon Sep 17 00:00:00 2001 From: "victormanuel.caverogracia" <> Date: Sun, 19 Jul 2026 14:18:11 +0200 Subject: [PATCH] analytics: track funnel goals (Signup, CheckoutStarted, Subscribed) via Plausible Add a small no-op-safe track() helper and emit three custom events so we can see where users drop off between landing and paid: Signup on auth callback, CheckoutStarted before the Stripe redirect, Subscribed on plan activation. Plausible here is Community Edition (no revenue goals), so the plan price rides along as a plain value_usd prop instead of a revenue field. Self-hosted builds without the analytics script are unaffected (track() no-ops). --- dashboard/index.html | 1 + dashboard/src/components/AccountPage.jsx | 21 ++++++++++++++++++++ dashboard/src/components/PricingSection.jsx | 19 +++++++++++++----- dashboard/src/contexts/AuthContext.jsx | 4 ++++ dashboard/src/lib/analytics.js | 22 +++++++++++++++++++++ 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 dashboard/src/lib/analytics.js diff --git a/dashboard/index.html b/dashboard/index.html index 6c7e04a..a62660a 100644 --- a/dashboard/index.html +++ b/dashboard/index.html @@ -191,6 +191,7 @@ +
diff --git a/dashboard/src/components/AccountPage.jsx b/dashboard/src/components/AccountPage.jsx index 55bf477..7cbd6fb 100644 --- a/dashboard/src/components/AccountPage.jsx +++ b/dashboard/src/components/AccountPage.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react'; import { Loader2, CreditCard, LogOut, Plus } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; import { apiJson } from '../lib/api'; +import { track } from '../lib/analytics'; const fmt1 = (n) => Math.round((n || 0) * 10) / 10; @@ -24,6 +25,26 @@ export default function AccountPage() { if ((data && data.plan) || tries > 15) { clearInterval(t); setActivating(false); + // Fire the Subscribed conversion goal. A pending-checkout stash (set in + // PricingSection) carries the plan price, so we can attach real revenue; + // top-ups don't set it, so they never count as a subscription. + if (data && data.plan) { + let pending = null; + try { pending = JSON.parse(localStorage.getItem('os_pending_checkout') || 'null'); } catch (_) { /* ignore */ } + if (pending) { + // This Plausible is Community Edition, which has no revenue goals — + // so the price rides along as plain props (value_usd / plan) that CE + // can break the goal down by. The exact MRR still lives in Stripe. + track('Subscribed', { + props: { + plan: pending.plan, + interval: pending.interval, + value_usd: Math.round((pending.amount || 0) / 100), + }, + }); + try { localStorage.removeItem('os_pending_checkout'); } catch (_) { /* ignore */ } + } + } // First time a plan activates, take the user straight to connect their // socials. Guard with a flag so top-up checkouts don't re-trigger it. if (data && data.plan && !localStorage.getItem('os_socials_prompted')) { diff --git a/dashboard/src/components/PricingSection.jsx b/dashboard/src/components/PricingSection.jsx index 0f138f4..249be1a 100644 --- a/dashboard/src/components/PricingSection.jsx +++ b/dashboard/src/components/PricingSection.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Check, Loader2, Zap, Github, Server } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; import { apiJson } from '../lib/api'; +import { track } from '../lib/analytics'; import SegmentedControl from './ui/SegmentedControl'; const PLAN_ORDER = ['starter', 'creator', 'pro']; @@ -30,14 +31,22 @@ export default function PricingSection({ onRequireLogin }) { .finally(() => setLoading(false)); }, []); - const checkout = async (price_id) => { - if (!isSignedIn) { onRequireLogin?.(price_id); return; } - setBusyPrice(price_id); + const checkout = async (entry) => { + if (!isSignedIn) { onRequireLogin?.(entry.price_id); return; } + setBusyPrice(entry.price_id); + track('CheckoutStarted', { props: { plan: entry.plan, interval: entry.interval } }); + // Stash the price so we can attach real revenue to the Subscribed goal when + // the user returns from Stripe (see AccountPage's checkout=success handler). + try { + localStorage.setItem('os_pending_checkout', JSON.stringify({ + plan: entry.plan, interval: entry.interval, amount: entry.amount, currency: entry.currency, + })); + } catch (_) { /* ignore storage errors */ } try { const { url } = await apiJson('/api/billing/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ price_id }), + body: JSON.stringify({ price_id: entry.price_id }), }); window.location.href = url; } catch (e) { @@ -94,7 +103,7 @@ export default function PricingSection({ onRequireLogin }) { {plan === 'pro' &&