senternet-site-posthog

Integrates PostHog product analytics into Vite React and Next.js sites with lazy loading.

Updated May 8, 2026
One-click install
npx skills add https://github.com/MattSenter/senternet-site-skills --skill senternet-site-posthog-mattsenter
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: senternet-site-posthog
Source: https://github.com/MattSenter/senternet-site-skills/tree/main/.claude/skills/senternet-site-posthog
Command: npx skills add https://github.com/MattSenter/senternet-site-skills --skill senternet-site-posthog-mattsenter

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires posthog-js.

What problem does it solve? Adding product analytics to a marketing site often hurts page performance, leaks PII, or fires events in development environments. This Skill wires PostHog Cloud into a Vite + React or Next.js site with browser-only lazy loading, production gating, and non-PII event tracking. ## Core Features & Use Cases - Gated Initialization: Loads posthog-js dynamically only in production builds with a configured project API key, keeping dev and prerender output free of PostHog traffic. - Centralized Event Capture: Routes all events through a single analytics helper so payloads stay consistent and non-PII, with autocapture disabled by default. - Framework Tracks: Covers both Vite + React (VITE_* env vars, init after mount) and Next.js (NEXT_PUBLIC_* vars, client provider, pathname-based pageview capture). - Use Case: You have a production marketing site and want funnel and retention analytics without blocking first paint or sending user data — this Skill sets up the env vars, helper module, and validation checks. ## Quick Start Set up PostHog analytics on my Vite React site with production-only lazy loading and non-PII event tracking.

Frequently Asked Questions about senternet-site-posthog

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

FAQPage Schema
How do I add PostHog analytics to a Vite React app?▼

Install posthog-js, store the project API key and host in VITE_POSTHOG_KEY and VITE_POSTHOG_HOST env vars, and create a helper that dynamically imports posthog-js only in production. Call the init function from a top-level useEffect so it runs after first paint.

How do I set up PostHog in a Next.js app?▼

Use NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST env vars and initialize PostHog inside a 'use client' provider mounted from app/layout.tsx, guarded on typeof window. Capture pageviews on usePathname and useSearchParams changes since automatic capture misses client-side navigations.

How do I prevent PostHog from loading in development?▼

Gate initialization on import.meta.env.PROD combined with a configured API key, and set real values only in .env.production. With this setup, dev builds produce no requests to the PostHog host in the network tab.

Does PostHog autocapture risk collecting PII?▼

Yes, autocapture can sweep up form values and text content, so this setup leaves it off by default. Events are sent through a single capture helper limited to non-PII metadata like provider types, counts, flags, and section names.

Why does PostHog not track pageviews on Next.js client-side navigation?▼

PostHog's automatic pageview capture only sees the initial document load, not client-side route changes. Track pageviews manually on usePathname or useSearchParams changes, wrapping the search params reader in Suspense to avoid opting the route into dynamic rendering.