integration-astro-ssr

Integrate PostHog analytics into Astro server-rendered apps with API routes.

58|5|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/PostHog/skills --skill integration-astro-ssr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: integration-astro-ssr
Source: https://github.com/PostHog/skills/tree/main/skills/posthog/integration/skills/astro-ssr
Command: npx skills add https://github.com/PostHog/skills --skill integration-astro-ssr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

PostHog analytics integration for server-rendered Astro apps with API routes to enable both client-side and server-side tracking.

Core Features & Use Cases

  • Client-side event tracking with the PostHog snippet in Astro components
  • Server-side event capture via API routes and a PostHog server singleton
  • User identification across frontend and backend to correlate sessions
  • Reusable layout and components pattern for applying analytics across pages

Quick Start

Follow the workflow in the references to wire up PostHog in an Astro SSR project, including environment configuration and example API routes.

Frequently Asked Questions about integration-astro-ssr

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I integrate PostHog analytics into an Astro SSR app?

To integrate PostHog analytics into an Astro SSR app, you use a reusable layout for client-side snippet initialization and API routes to wire up a server singleton for server-side event capture.

Can I track both client-side and server-side events with PostHog in Astro?

Yes, you can track both client-side and server-side events by combining the PostHog snippet in Astro components with a server singleton event capture mechanism within your API routes.

How do I maintain user session continuity across frontend and backend in Astro?

You maintain session continuity by implementing user identification across frontend and backend, correlating distinct client-side sessions with server-side event captures processed through API routes.

What's the best way to configure PostHog environment variables for Astro server-rendered apps?

The best way to configure PostHog environment variables is to set them during project setup, enabling the server singleton initialization and client-side snippet configuration to securely access API keys.

Does PostHog server-side tracking work with Astro API routes?

Yes, PostHog server-side tracking works with Astro API routes by utilizing a dedicated server singleton to capture backend events while maintaining correlated user identification.

Why do I need a reusable layout pattern for Astro analytics?

You need a reusable layout pattern to consistently apply the PostHog client initialization snippet across all pages, ensuring uniform client-side event tracking and session continuity without duplicate code.