Astro SSR PostHog Integration
Integrates PostHog analytics and session tracking into server-rendered Astro applications and API routes.
This skill provides a standardized approach for implementing PostHog analytics within Astro applications using Server-Side Rendering (SSR). It guides the setup of client-side tracking via reusable Astro components and server-side event logging through API routes. By implementing best practices such as singleton patterns for server clients, session correlation via custom headers, and environment variable security, it ensures robust, end-to-end user behavioral data collection without disrupting existing application architecture.
Key Features
01Server-side event tracking via posthog-node singleton pattern
02Secure environment variable management for project tokens
03Unified tracking across client-side pages and server-side API routes
04Session and user identity correlation using custom X-PostHog headers
0542 GitHub stars
06Automated creation of reusable posthog.astro components
Use Cases
01Correlating backend API events with frontend user sessions in Astro apps
02Implementing server-side error tracking and feature flags within Astro API routes
03Tracking user behavior across server-rendered marketing sites and authenticated dashboards