PostHog Analytics
PostHog is the open-source analytics platform wired into Flux Theme. Track every page view, product interaction, checkout step, and purchase — all without sending your data to third parties. posthog-js is already listed in your dependencies.
Create a Project & Add Your Key
Sign up at posthog.com, create a new project, and copy your Project API key. Add it to your .env file — Flux reads it via import.meta.env so it's never hard-coded.
Wire It Into the Flux Layout
Flux Theme uses a BaseHead.astro component loaded on every page. Drop the Analytics component there so PostHog initialises once and auto-captures every route change.
Template-Specific Events to Track
Flux ships with e-commerce, blog, and SaaS pages. Here are the key events to capture across the template so you can build funnels that actually mean something.
| Event | Where to fire it | Key properties |
|---|---|---|
| hero_cta_clicked | src/components/hero/Hero.jsx | variant, page |
| template_viewed | src/components/pages/Gallery.jsx | slug, category, price |
| buy_button_clicked | src/components/pages/Gallery.jsx | slug, price |
| checkout_started | Polar.sh redirect handler | plan, amount |
| purchase_completed | Stripe / Polar webhook | plan, amount, currency |
| post_read | src/pages/blog/[slug].astro | slug, read_time_seconds |
| sign_up_completed | Clerk onSignUp callback | method |