Skip to content
cccskills
FreePublished on GitHub

adding-analytics

Add PostHog analytics to a web application, including event tracking, page views, feature flags, and session replay.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md2.6 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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:

      "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.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Use Cursor's browser aria snapshots to audit a page for accessibility issues — missing labels, broken tab order, contrast, and ARIA misuse.

The English summary is being prepared. Showing the original description.

0xAidan/polymarket-bot-test4Updated Sep 4, 2026

Generate OpenAPI/Swagger documentation for an API, including endpoint schemas, request/response types, and interactive docs UI.

The English summary is being prepared. Showing the original description.

0xAidan/polymarket-bot-test4Updated Sep 4, 2026

Add authentication to a web application using NextAuth.js (Auth.js), including OAuth providers, session management, and protected routes.

The English summary is being prepared. Showing the original description.

0xAidan/polymarket-bot-test4Updated Sep 4, 2026

Dockerize an application with a production-ready Dockerfile, docker-compose setup, and .dockerignore.

The English summary is being prepared. Showing the original description.

0xAidan/polymarket-bot-test4Updated Sep 4, 2026

Set up Playwright end-to-end testing in a project, including test configuration, example tests, and CI integration.

The English summary is being prepared. Showing the original description.

0xAidan/polymarket-bot-test4Updated Sep 4, 2026

Add Sentry error tracking, performance monitoring, and source maps to a web application.

The English summary is being prepared. Showing the original description.

0xAidan/polymarket-bot-test4Updated Sep 4, 2026

See all skills by 0xAidan

Report a problem with this skill