integration-sveltekit

Integrate PostHog analytics into SvelteKit apps for client and server event tracking.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This integration enables PostHog analytics within SvelteKit projects, providing seamless observability and consistent event tracking across client and server sides.

Core Features & Use Cases

  • Client-side PostHog initialization and user identification in SvelteKit components.
  • Server-side event capture using PostHog Node SDK with proper shutdown handling and error tracking.
  • SSR-friendly configuration and guidance for session replay with relative asset paths in SvelteKit.

Quick Start

Install the required PostHog libraries, configure environment variables, and initialize PostHog in both client and server contexts following the example.

Frequently Asked Questions about integration-sveltekit

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

FAQPage Schema
How do I integrate PostHog analytics into a SvelteKit app?

Integrating PostHog into SvelteKit requires installing PostHog libraries, configuring environment variables for keys, and initializing tracking in both client and server contexts. This enables seamless end-to-end event tracking.

How do I set up PostHog session replay in SvelteKit with SSR?

PostHog session replay in SvelteKit requires SSR-friendly configuration using relative asset paths. This setup ensures session recordings load correctly during server-side rendering without breaking hydration.

Can I capture server-side events using the PostHog Node SDK in SvelteKit?

You can capture server-side events using the PostHog Node SDK in SvelteKit. This requires proper shutdown handling and error tracking to ensure events flush correctly before the server process terminates.

Do I need a reverse proxy to configure PostHog in SvelteKit?

An SSR-safe configuration for PostHog in SvelteKit uses a reverse proxy. This setup requires environment-based configuration for PostHog keys to route analytics requests securely and avoid CORS issues.

What is the best way to handle user identification for PostHog in SvelteKit?

User identification for PostHog in SvelteKit is handled through client-side initialization within components. This approach applies consistent identity tracking across both client and server-side flows.

Why does my PostHog SvelteKit integration need environment-based configuration?

PostHog SvelteKit integration requires environment-based configuration for keys to maintain security. This follows repository conventions for organizing scripts and ensures consistent naming across server and client contexts.