Skip to main content
skill CX Codex

adding-analytics — Claude Code skill: what it does, how to install

Guides the AI agent in setting up PostHog analytics, page view tracking, feature flags, and session replay across web apps.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add spencerpauly/awesome-cursor-skills --skill adding-analytics -a claude-code
Open on GitHub

What adding-analytics does

The skill inspects configuration files like next.config.*, vite.config.*, or package.json to detect the framework. It covers Next.js, React, Vue, and Svelte. For backend telemetry, it installs posthog-node or the Python posthog package.

The agent creates an initialization module, such as app/providers.tsx with PostHogProvider for Next.js App Router or an initialization hook in _app.tsx. In single-page applications, route changes trigger manual $pageview captures. It also sets up feature flags through isFeatureEnabled and configures session recording.

You must provide NEXT_PUBLIC_POSTHOG_KEY and host settings in .env. In monorepos, install the client dependency directly into the UI package rather than the root workspace. Projects with a Content Security Policy must explicitly allow posthog-js endpoints.

What it helps with

  • integrate PostHog into Next.js or React applications
  • track single-page app route changes manually
  • wire custom event handlers for user actions
  • enable session replay and PostHog feature flags

Example prompts for the agent

  • Add PostHog analytics to our Next.js App Router project
  • Track signup button clicks as custom PostHog events
  • Set up session replay and feature flags using PostHog

How to install adding-analytics

1Skills CLI (Vercel)

npx skills add spencerpauly/awesome-cursor-skills --skill adding-analytics -a claude-code

2Manually: put the files in place

~/.claude/skills/adding-analytics/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/adding-analytics/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about adding-analytics

How to install adding-analytics in Claude Code?

Run npx skills add spencerpauly/awesome-cursor-skills --skill adding-analytics -a claude-code. You can also save the file directly to ~/.claude/skills/adding-analytics/SKILL.md.

What does adding-analytics do?

It guides the agent through SDK installation, framework detection, root provider configuration, and event tracking setup for PostHog.

What is required before integrating PostHog?

You need your PostHog project API key and host address ready for .env. If your project uses a Content Security Policy, you must add PostHog to it.

Source text

SKILL.md · CC0-1.0
---
name: adding-analytics
description: Add PostHog analytics to a web application, including event tracking, page views, feature flags, and session replay.
---

# Add Analytics (PostHog)

Use this skill when the user asks to add analytics, event tracking, page views, feature flags, or session replay to a web application.

## Steps

1. **Detect the framework** — check for `next.config.*`, `vite.config.*`, `package.json` scripts, or `index.html` to determine if this is Next.js, React (Vite/CRA), Vue, Svelte, or plain HTML.

2. **Install the SDK**

   - Next.js / React: `npm install posthog-js`
   - Next.js (server-side): `npm install posthog-js posthog-node`
   - Python: `pip install posthog`
   - Node.js backend: `npm install posthog-node`

3. **Create a provider / init module**

   - For Next.js App Router, create `app/providers.tsx`:

     ```tsx
     "use client";
     import posthog from "posthog-js";
     import { PostHogProvider as PHProvider } from "posthog-js/react";
     import { useEffect } from "react";

     export function PostHogProvider({ children }: { children: React.ReactNode }) {
       useEffect(() => {
         posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
           api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST ?? "https://us.i.posthog.com",
           capture_pageview: false, // we capture manually for SPAs
         });
       }, []);
       return <PHProvider client={posthog}>{children}</PHProvider>;
     }
     ```

   - Wrap `{children}` in the root layout with `<PostHogProvider>`.

   - For Pages Router, init in `_app.tsx` inside a `useEffect`.

4. **Add page-view tracking** — for SPAs, create a component that calls `posthog.capture('$pageview')` on route change using the framework's router events.

5. **Add `.env` variables** — prompt the user for their PostHog project API key and host:

   ```
   NEXT_PUBLIC_POSTHOG_KEY=phc_...
   NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
   ```

   Add these keys to `.env.example` as well.

6. **Add custom events** — if the user specifies events to track (e.g. sign-up, purchase), add `posthog.capture("event_name", { ...properties })` calls in the relevant handlers.

7. **Feature flags (optional)** — if requested, show how to use `posthog.isFeatureEnabled("flag-name")` or the `useFeatureFlagEnabled` hook.

8. **Session replay (optional)** — enable by adding `session_recording: { maskAllInputs: false }` to the init config if requested.

## Notes

- Never hardcode API keys — always use environment variables.
- Add `posthog-js` to the Content Security Policy if the project has one.
- For monorepos, install in the package that renders the UI, not the root.

© spencerpauly · CC0-1.0 · spencerpauly/awesome-cursor-skills

Similar skills

Everything for Frontend and UI →

From the same set59

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor