{"slug":"adding-analytics","title":"adding-analytics","summary":"Add PostHog analytics to a web application, including event tracking, page views, feature flags, and session replay.","platform":"Cursor","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-08-12T22:23:27.338523Z","repo":{"url":"https://github.com/spencerpauly/awesome-cursor-skills","stars":896,"forks":220,"license":"CC0-1.0","updatedAt":"2026-08-02T02:41:53Z"},"bodyHtml":"<hr>\n<h2>name: adding-analytics\ndescription: Add PostHog analytics to a web application, including event tracking, page views, feature flags, and session replay.</h2>\n<h1>Add Analytics (PostHog)</h1>\n<p>Use this skill when the user asks to add analytics, event tracking, page views, feature flags, or session replay to a web application.</p>\n<h2>Steps</h2>\n<ol>\n<li><p><strong>Detect the framework</strong> — check for <code>next.config.*</code>, <code>vite.config.*</code>, <code>package.json</code> scripts, or <code>index.html</code> to determine if this is Next.js, React (Vite/CRA), Vue, Svelte, or plain HTML.</p>\n</li>\n<li><p><strong>Install the SDK</strong></p>\n<ul>\n<li>Next.js / React: <code>npm install posthog-js</code></li>\n<li>Next.js (server-side): <code>npm install posthog-js posthog-node</code></li>\n<li>Python: <code>pip install posthog</code></li>\n<li>Node.js backend: <code>npm install posthog-node</code></li>\n</ul>\n</li>\n<li><p><strong>Create a provider / init module</strong></p>\n<ul>\n<li><p>For Next.js App Router, create <code>app/providers.tsx</code>:</p>\n<pre><code>\"use client\";\nimport posthog from \"posthog-js\";\nimport { PostHogProvider as PHProvider } from \"posthog-js/react\";\nimport { useEffect } from \"react\";\n\nexport function PostHogProvider({ children }: { children: React.ReactNode }) {\n  useEffect(() =&gt; {\n    posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n      api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST ?? \"https://us.i.posthog.com\",\n      capture_pageview: false, // we capture manually for SPAs\n    });\n  }, []);\n  return &lt;PHProvider client={posthog}&gt;{children}&lt;/PHProvider&gt;;\n}\n</code></pre>\n</li>\n<li><p>Wrap <code>{children}</code> in the root layout with <code>&lt;PostHogProvider&gt;</code>.</p>\n</li>\n<li><p>For Pages Router, init in <code>_app.tsx</code> inside a <code>useEffect</code>.</p>\n</li>\n</ul>\n</li>\n<li><p><strong>Add page-view tracking</strong> — for SPAs, create a component that calls <code>posthog.capture('$pageview')</code> on route change using the framework's router events.</p>\n</li>\n<li><p><strong>Add <code>.env</code> variables</strong> — prompt the user for their PostHog project API key and host:</p>\n<pre><code>NEXT_PUBLIC_POSTHOG_KEY=phc_...\nNEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com\n</code></pre>\n<p>Add these keys to <code>.env.example</code> as well.</p>\n</li>\n<li><p><strong>Add custom events</strong> — if the user specifies events to track (e.g. sign-up, purchase), add <code>posthog.capture(\"event_name\", { ...properties })</code> calls in the relevant handlers.</p>\n</li>\n<li><p><strong>Feature flags (optional)</strong> — if requested, show how to use <code>posthog.isFeatureEnabled(\"flag-name\")</code> or the <code>useFeatureFlagEnabled</code> hook.</p>\n</li>\n<li><p><strong>Session replay (optional)</strong> — enable by adding <code>session_recording: { maskAllInputs: false }</code> to the init config if requested.</p>\n</li>\n</ol>\n<h2>Notes</h2>\n<ul>\n<li>Never hardcode API keys — always use environment variables.</li>\n<li>Add <code>posthog-js</code> to the Content Security Policy if the project has one.</li>\n<li>For monorepos, install in the package that renders the UI, not the root.</li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":2691,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"notes-only","suspicious":0,"notes":4,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-08-12T22:23:41.489194Z","sha256":"D39E8C98D51BE8CDD888907BD2375E902FE7121701403637B7AA861D51FF89F7","sizeBytes":1385},"review":null,"source":{"repositoryUrl":"https://github.com/spencerpauly/awesome-cursor-skills","path":"resources/adding-analytics","license":"CC0-1.0","commit":"99cd2655788456cc1c685944dcf8c2de82c1ded4","subtreeSha":"0AC705F68A0AB9DBBB296D0CD748CCF0E0BCBE834D5A87BDB7843A8C99588059","lastSyncedAt":"2026-11-19T20:53:18.054981Z"},"reviewedAt":"2026-08-12T22:24:01.610197Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/spencerpauly/awesome-cursor-skills/tree/main/resources/adding-analytics"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install spencerpauly-awesome-cursor-skills@llmmart"},{"target":"git","command":"git clone https://github.com/spencerpauly/awesome-cursor-skills.git"}]}