integration-astro-ssr — Claude Code skill: setup guide
integration-astro-ssr adds PostHog analytics to server-rendered Astro setups with API endpoints. Connects frontend tracking with backend routes.
MIT 109 installs ★ 80 updated 2026-10-24
npx skills add PostHog/skills --skill integration-astro-ssr -a claude-codeWhat integration-astro-ssr does
The skill outlines a four-stage workflow to embed analytics into server-side Astro projects. It instructs the assistant to build a shared src/components/posthog.astro template and inject it through a root layout. Client script tags receive the is:inline attribute to prevent Astro from parsing them and throwing TypeScript build errors.
For server endpoints under src/pages/api/, tracking relies on the posthog-node library. The instructions enforce a singleton setup inside src/lib/posthog-server.ts to stop API routes from spinning up redundant instances.
Cross-boundary tracking passes X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers from frontend calls into backend handlers. Hardcoding API tokens is strictly forbidden; public keys must adopt the PUBLIC_ prefix in environment files.
What it helps with
- set up PostHog tracking in SSR Astro applications
- correlate frontend sessions with backend API requests via custom headers
- configure a posthog-node singleton for server endpoints
- embed error tracking across critical user flows and API boundaries
Example prompts for the agent
- Integrate PostHog into this Astro SSR project following the official pattern
- Set up posthog-node singleton for our Astro API routes
- Add user identification across Astro frontend and backend endpoints
How to install integration-astro-ssr
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-astro-ssr -a claude-code2Manually: put the files in place
~/.claude/skills/integration-astro-ssr/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/integration-astro-ssr/
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-astro-ssr -a codex2Manually: put the files in place
.agents/skills/integration-astro-ssr/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-astro-ssr -a cursor2Manually: put the files in place
.cursor/skills/integration-astro-ssr/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PostHog/skills skills/posthog/all/skills/integration-astro-ssr2Manually: put the files in place
.github/skills/integration-astro-ssr/SKILL.md1Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-astro-ssr -a gemini-cli2Platform CLI
gemini skills install https://github.com/PostHog/skills --path skills/posthog/all/skills/integration-astro-ssrManually: put the files in place
.devin/skills/integration-astro-ssr/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PostHog/skills --skill integration-astro-ssr -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about integration-astro-ssr
How to install integration-astro-ssr in Claude Code?
Run npx skills add PostHog/skills --skill integration-astro-ssr -a claude-code in your workspace.
What does integration-astro-ssr do?
It guides code assistants through integrating PostHog client scripts and posthog-node server handlers into Astro SSR projects.
Why does the skill require the is:inline directive?
Astro parses standard script tags by default, which triggers TypeScript compilation errors on PostHog snippet code.
Source text
SKILL.md · MIT
--- name: integration-astro-ssr description: PostHog integration for server-rendered Astro applications with API routes metadata: author: PostHog version: 1.9.4 --- # PostHog integration for Astro (SSR) This skill helps you add PostHog analytics to Astro (SSR) applications. ## Workflow Follow these steps in order to complete the integration: 1. `basic-integration-1.0-begin.md` - PostHog Setup - Begin ← **Start here** 2. `basic-integration-1.1-edit.md` - PostHog Setup - Edit 3. `basic-integration-1.2-revise.md` - PostHog Setup - Revise 4. `basic-integration-1.3-conclude.md` - PostHog Setup - Conclusion ## Reference files - `references/EXAMPLE.md` - Astro (SSR) example project code - `references/astro.md` - Astro - docs - `references/identify-users.md` - Identify users - docs - `references/basic-integration-1.0-begin.md` - PostHog setup - begin - `references/basic-integration-1.1-edit.md` - PostHog setup - edit - `references/basic-integration-1.2-revise.md` - PostHog setup - revise - `references/basic-integration-1.3-conclude.md` - PostHog setup - conclusion The example project shows the target implementation pattern. Consult the documentation for API details. ## Key principles - **Environment variables**: Always use environment variables for PostHog keys. Never hardcode them. - **Minimal changes**: Add PostHog code alongside existing integrations. Don't replace or restructure existing code. - **Match the example**: Your implementation should follow the example project's patterns as closely as possible. ## Framework guidelines - Always use the is:inline directive on PostHog script tags to prevent Astro from processing them and causing TypeScript errors - Use PUBLIC_ prefix for client-side environment variables in Astro (e.g., PUBLIC_POSTHOG_PROJECT_TOKEN) - Create a posthog.astro component in src/components/ for reusable initialization across pages - Import the PostHog component in a Layout and wrap all pages with that layout - Use posthog-node in API routes under src/pages/api/ for server-side event tracking - Store the posthog-node client instance in a singleton pattern (src/lib/posthog-server.ts) to avoid creating multiple clients - Pass the client session ID to server via X-PostHog-Session-Id header for unified session tracking ## Identifying users Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID` headers to maintain correlation. ## Error tracking Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.
© PostHog · MIT · PostHog/skills