Claude Templates / A-tier · High leverage
Growth & SEO
The Customer Analytics Playbook
First-party event tracking that outlives cookie blockers and costs nothing per event.
CUSTOMER-ANALYTICS-PLAYBOOK.md · 14 sections · 2,384 words · 19 KB · markdown
By Moe Ameen, founder of BILT · Published · Updated
The Customer Analytics Playbook has Claude Code build first-party event tracking in Supabase instead of a third-party analytics tool: page_events and visitor tables with an atomic upsert, a rate-limited and bot-filtered /api/track route, visitor IDs in a cookie plus sessionStorage, first-touch UTM capture, signup attribution, and a churn-risk flag that turns orange at 7 days without usage and red at 14.
Key takeaways
- Tracking writes to your own Supabase tables through /api/track.
- Keep the taxonomy small: the file says 5-10 events, not 500.
- UTMs are captured first-touch and never overwritten.
- Churn risk flags at 7 and 14 days of zero usage.
Own your funnel data. A single page_events table, a hardened /api/track ingest route, visitor-ID rotation, bot filtering, and signup attribution that survives the referrer being stripped. One source of truth that powers the landing-page HUD, the admin dashboard, and every conversion report.
What does the Customer Analytics Playbook build?
It builds the data collection side of analytics: ingest, visitor and session IDs, attribution from anonymous visitor to signed-up user, and a public live-counter feed for landing pages.
The Admin Analytics Dashboard playbook builds the screens that read this data.
When should you set up first-party analytics?
Set it up in week 4, before you start guessing about where signups come from. Section 1 of the file explains why it prefers first-party over GA, Mixpanel or Segment for this kind of app.
If you need cross-device product analytics with cohorts out of the box, a hosted tool may still be faster.
What do you need first?
You need App Infrastructure, a Supabase project with its service-role key, the landing page where live counters will show, and your list of 5-10 event names.
Churn signals only mean something if a subscriptions table exists, so Stripe Billing helps.
What's inside
What does the playbook give you?
- //The page_events schema and the event taxonomy that goes in it
- //A hardened /api/track ingest route with bot filtering
- //visitor_id rotation + the anonymous → identified stitch on signup
- //Signup attribution: UTM capture, referrer classification, AI-source recovery
- //Funnel-step modeling that stays in lockstep across the code
- //Why first-party beats Mixpanel/Amplitude at this scale
When to use it
Week 4, before you start guessing about the funnel.
Build these first
Straight from the file
What does the writing look like?
Trade-off you accept: no out-of-the-box "session replay" or "heatmap." If you need those, layer PostHog OSS on top — but the ingest stays first-party.
Table of contents
Which sections does the file cover?
- 0. Use this spec
- 1. Why first-party (vs GA / Mixpanel / Segment)
- 2. Architecture
- 3. Schema (Supabase)
- 4. The atomic upsert RPC
- 5. /api/track ingest
- 6. Visitor + session IDs
- 7. Signup attribution (don't break visitor stability)
- 8. Event taxonomy (5–10 events, not 500)
- 9. /api/metrics/live (public HUD counters)
- 10. Admin analytics dashboard
- 11. Churn-risk signal
- 12. Common pitfalls
- 13. Kickoff prompt
How do you run it?
Drop CUSTOMER-ANALYTICS-PLAYBOOK.md into your repo, then tell Claude Code: “Read CUSTOMER-ANALYTICS-PLAYBOOK.md and implement it in this codebase.” It's written for an agent to execute end to end. Search the file for angle-bracket placeholders and swap in your own project names, domains, and keys before the first run.
Who is this for, and who should skip it?
Best for
- Apps that want funnel data in their own database
- Founders who need signup attribution, including AI-assistant referrals
- Teams avoiding per-event analytics pricing
Not ideal for
- Teams that need heatmaps or session replay
- Apps already well served by GA4 or Mixpanel
- Products with no web front end
- Builders who won't adapt paths: the file points to a reference app you won't have
What else do people ask?
Which events does the Customer Analytics Playbook track?
The Customer Analytics Playbook suggests page_view, cta_click, opt_in, signup_complete, onboarding_complete, a first-action marker such as first_generation, checkout_start, checkout_complete and scroll_depth. Anything more specific goes in the metadata JSON instead of a new event name, like cta_click with metadata.cta_id = "hero_primary".
Does it work without Supabase or Vercel?
The Customer Analytics Playbook is written for Supabase Postgres: the schema, RLS policies and atomic upsert RPC are Supabase SQL, and writes go through the service-role key. Country, region and city come from Vercel geo headers, and the file doesn't cover other databases or hosts.
Do I get session replay or heatmaps?
No. The Customer Analytics Playbook accepts the lack of session replay and heatmaps as a trade-off. If you need them, it suggests layering PostHog OSS on top while keeping ingest first-party.
What is in the Customer Analytics Playbook download?
The Customer Analytics Playbook is a markdown file of about 2,400 words. It includes SQL for the page_events and page_event_visitors tables with indexes and RLS, the upsert_visitor_event function and a user_churn_risk materialized view, plus a file tree, the event taxonomy, the /api/track rules and a kickoff prompt.
Should I overwrite the visitor ID with the user ID at signup?
No. The Customer Analytics Playbook keeps visitor_id stable at signup and links it to the account through the user_id pointer on page_event_visitors. Overwriting the cookie breaks attribution across signup and shows up as a fake new visitor in the next day's funnel.
How do we know this?
This page is based on the playbook file itself, CUSTOMER-ANALYTICS-PLAYBOOK.md, which Moe Ameen wrote from the Kompozy codebase (called BKE in the file). We read the file on November 4, 2026; the facts here come from it, not from independent testing in other codebases.
More growth & seo playbooks
Topical Authority
The 5-layer model that turns a marketing site into 250-350 pages that actually rank.
Read + download →A-tierSEO/GEO Engine
The autonomous layer: trend discovery, LLM classification, auto-authored pages, tracking.
Read + download →A-tierPre-Sale Chatbot
A grounded pre-sale assistant that builds its own knowledge base on install.
Read + download →