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.

.env

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.

src/components/Analytics.jsx

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.

Terminal
EventWhere to fire itKey properties
hero_cta_clickedsrc/components/hero/Hero.jsxvariant, page
template_viewedsrc/components/pages/Gallery.jsxslug, category, price
buy_button_clickedsrc/components/pages/Gallery.jsxslug, price
checkout_startedPolar.sh redirect handlerplan, amount
purchase_completedStripe / Polar webhookplan, amount, currency
post_readsrc/pages/blog/[slug].astroslug, read_time_seconds
sign_up_completedClerk onSignUp callbackmethod