integration-astro-view-transitions

Integrate PostHog analytics into Astro apps with ClientRouter view transitions.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

PostHog integration for Astro with ClientRouter view transitions requires guards to prevent multiple initializations and to track pageviews during soft navigations.

Core Features & Use Cases

  • Initialization guard for view transitions
  • ClientRouter layout with PostHog
  • User identification and event tracking
  • Error tracking and reset on logout
  • Environment variable configuration and Astro components guidance

Quick Start

Configure your environment variables and wrap your Astro app with the PostHog view-transitions layout to enable guarded initialization and automatic pageview tracking.

Frequently Asked Questions about integration-astro-view-transitions

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

FAQPage Schema
How do I integrate PostHog analytics into an Astro app using view transitions?

To integrate PostHog analytics into an Astro app using view transitions, wrap your pages in a reusable layout with ClientRouter and add an inline PostHog snippet wrapped in an initialization guard to prevent duplicate loading.

Why does PostHog initialize multiple times with Astro ClientRouter view transitions?

PostHog initializes multiple times with Astro ClientRouter view transitions because soft navigations re-execute scripts. A guarded initialization pattern prevents this by checking if the script already exists before loading the PostHog snippet again.

How do I track pageviews during Astro soft navigations with PostHog?

To track pageviews during Astro soft navigations with PostHog, use a ClientRouter layout pattern that captures pageview events automatically when view transitions occur, ensuring accurate tracking across route changes.

Do I need environment variables to configure PostHog in my Astro project?

Yes, you need environment variables to configure PostHog in your Astro project. You must define variables for your PostHog host and project token to correctly authenticate and route analytics data from your inline snippet.

Can I identify users and track events with PostHog in an Astro view transitions app?

Yes, you can identify users and track events with PostHog in an Astro view transitions app. The integration supports user identification on login, custom event tracking, error tracking, and resetting user data on logout.

What are the limitations of adding PostHog to Astro without an initialization guard?

Adding PostHog to Astro without an initialization guard causes duplicate script execution during ClientRouter soft navigations, leading to multiple PostHog instances, inflated analytics data, and potential memory leaks.