integration-nextjs-app-router

Integrate PostHog analytics into Next.js App Router apps for client and server event tracking.

21|2|Updated Nov 5, 2023
One-click install
npx skills add https://github.com/motormetrics/motormetrics --skill integration-nextjs-app-router-motormetrics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: integration-nextjs-app-router
Source: https://github.com/motormetrics/motormetrics/tree/main/apps/web/.claude/skills/integration-nextjs-app-router
Command: npx skills add https://github.com/motormetrics/motormetrics --skill integration-nextjs-app-router-motormetrics

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Enables seamless PostHog analytics integration in Next.js App Router apps, providing end-to-end visibility across client and server boundaries.

Core Features & Use Cases

  • Client-side tracking via posthog-js inside instrumentation-client.ts to capture events and identify users.
  • Server-side analytics via posthog-node for API routes and server components, ensuring cross-domain correlation.
  • Error tracking, feature flags, and session identification across the app router architecture.

Quick Start

Install PostHog for Next.js, add instrumentation-client.ts, and initialize PostHog with your project token and host.

Frequently Asked Questions about integration-nextjs-app-router

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

FAQPage Schema
How do I integrate PostHog analytics into a Next.js App Router application?

To integrate PostHog analytics into a Next.js App Router application, initialize posthog-js in instrumentation-client.ts for client-side tracking and use posthog-node for server-side API routes. This setup enables environment-based configuration, cross-domain correlation, and user identification across the app router architecture.

How does server-side event tracking work with Next.js App Router and PostHog?

Server-side event tracking with Next.js App Router uses posthog-node within API routes and server components to capture events. This ensures cross-domain correlation between client boundaries, maintains session identification, and applies environment-based configuration for analytics data capture.

Does PostHog work with Next.js instrumentation-client for client-side tracking?

Yes, PostHog works with Next.js instrumentation-client.ts to enable client-side tracking. You initialize PostHog with your project token and host inside instrumentation-client, allowing you to capture user actions, identify users, and load feature flags directly within the App Router architecture.

What's the best way to track errors and feature flags in a Next.js App Router app?

The best way to track errors and feature flags in a Next.js App Router app is through PostHog integration. By configuring posthog-js and posthog-node, you capture errors, load feature flags, and track session identification across both client-side and server-side boundaries.

When do I need environment-based configuration for PostHog in Next.js?

You need environment-based configuration for PostHog in Next.js when setting up analytics across App Router pages and API routes. It ensures proper project token initialization, host routing, and correct server integration for capturing user actions and tracking errors.