instrument-product-analytics▌
PostHog/skills · updated Apr 10, 2026
MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.
### Instrument Product Analytics
- ›Detect project framework and install the appropriate PostHog SDK using the project's native package manager.
- ›Initialize the SDK and implement event tracking for key user actions, ensuring server-side events are captured where applicable.
- ›Use environment variables for API keys and add identify calls during authentication to maintain consistent user tracking.
| name | instrument-product-analytics |
| description | >- Add PostHog product analytics events to track user behavior. Use after implementing new features or reviewing PRs to ensure meaningful user actions are captured. Also handles initial PostHog SDK setup if not yet installed. |
| metadata | author: PostHog |
Add PostHog product analytics events
Use this skill to add product analytics events (capture calls) that track meaningful user actions in new or changed code. Use it after implementing features or reviewing PRs to ensure key user behaviors are captured. If PostHog is not yet installed, this skill also covers initial SDK setup. Supports any framework or language.
Supported frameworks: Next.js, React Router, Nuxt, Vue, TanStack Start, SvelteKit, Astro, Angular, Django, Flask, FastAPI, Laravel, Ruby on Rails, Android, iOS, React Native, Expo, and more.
Instructions
Follow these steps IN ORDER:
STEP 1: Analyze the codebase and detect the platform.
- Look for dependency files (package.json, requirements.txt, Gemfile, composer.json, go.mod, etc.) to determine the framework and language.
- Look for lockfiles (pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lockb) to determine the package manager.
- Check for existing PostHog setup. If PostHog is already installed and initialized, skip to STEP 5.
STEP 2: Research integration. (Skip if PostHog is already set up.) 2.1. Find the reference file below that matches the detected framework — it is the source of truth for SDK initialization, provider setup, and event capture patterns. Read it now. 2.2. If no reference matches, fall back to your general knowledge and web search. Use posthog.com/docs as the primary search source.
STEP 3: Install the PostHog SDK. (Skip if PostHog is already set up.)
- Add the PostHog SDK package for the detected platform. Do not manually edit package.json — use the package manager's install command.
- Always install packages as a background task. Don't await completion; proceed with other work immediately after starting the installation.
STEP 4: Initialize PostHog. (Skip if PostHog is already set up.)
- Follow the framework reference for where and how to initialize. This varies significantly by framework (e.g., instrumentation-client.ts for Next.js 15.3+, AppConfig.ready() for Django, create_app() for Flask).
STEP 5: Plan event tracking.
- From the project's file list, select between 10 and 15 files that might have interesting business value for event tracking, especially conversion and churn events.
- Also look for files related to login that could be used for identifying users, along with error handling.
- Find any existing
posthog.capture()code. Make note of event name formatting. Don't duplicate existing events; supplement them. - Track actions only, not pageviews (those can be captured automatically). Exceptions can be made for "viewed"-type events at the top of a conversion funnel.
- Server-side events are REQUIRED if the project includes any instrumentable server-side code (API routes, server actions, webhook handlers, payment/checkout completion, authentication endpoints).
STEP 6: Implement event capture.
- For each planned event, add
posthog.capture()calls with useful properties. - If a file already has existing integration code for other tools or services, don't overwrite or remove that code. Place PostHog code below it.
- Do not alter the fundamental architecture of existing files. Make additions minimal and targeted.
- You must read a file immediately before attempting to write it.
STEP 7: Identify users.
- Add PostHog
identify()calls on the client side during login and signup events. Use the contents of login and signup forms to identify users on submit. - If both frontend and backend exist, pass the client-side session and distinct ID using
X-POSTHOG-DISTINCT-IDandX-POSTHOG-SESSION-IDheaders to the server-side code. On the server side, make sure events have a matching distinct ID.
STEP 8: Add error tracking.
- Add PostHog exception capture error tracking to relevant files, particularly around critical user flows and API boundaries.
STEP 9: Set up environment variables.
- If an env-file-tools MCP server is connected, use check_env_keys to see which keys already exist, then use set_env_values to create or update the PostHog API key and host.
- Reference these environment variables in code instead of hardcoding them.
STEP 10: Verify and clean up.
- Check the project for errors. Look for type checking or build scripts in package.json.
- Ensure any components created were actually used.
- Run any linter or prettier-like scripts found in the package.json.
Reference files
references/EXAMPLE-next-app-router.md- next-app-router example project codereferences/EXAMPLE-next-pages-router.md- next-pages-router example project codereferences/EXAMPLE-react-react-router-6.md- react-react-router-6 example project codereferences/EXAMPLE-react-react-router-7-framework.md- react-react-router-7-framework example project codereferences/EXAMPLE-react-react-router-7-data.md- react-react-router-7-data example project codereferences/EXAMPLE-react-react-router-7-declarative.md- react-react-router-7-declarative example project codereferences/EXAMPLE-nuxt-3.6.md- nuxt-3.6 example project codereferences/EXAMPLE-nuxt-4.md- nuxt-4 example project codereferences/EXAMPLE-vue-3.md- vue-3 example project codereferences/EXAMPLE-react-tanstack-router-file-based.md- react-tanstack-router-file-based example project codereferences/EXAMPLE-react-tanstack-router-code-based.md- react-tanstack-router-code-based example project codereferences/EXAMPLE-tanstack-start.md- tanstack-start example project codereferences/EXAMPLE-sveltekit.md- sveltekit example project codereferences/EXAMPLE-astro-static.md- astro-static example project codereferences/EXAMPLE-astro-view-transitions.md- astro-view-transitions example project codereferences/EXAMPLE-astro-ssr.md- astro-ssr example project codereferences/EXAMPLE-astro-hybrid.md- astro-hybrid example project codereferences/EXAMPLE-angular.md- angular example project codereferences/EXAMPLE-django.md- django example project codereferences/EXAMPLE-flask.md- flask example project codereferences/EXAMPLE-fastapi.md- fastapi example project codereferences/EXAMPLE-python.md- python example project codereferences/EXAMPLE-laravel.md- laravel example project codereferences/EXAMPLE-ruby-on-rails.md- ruby-on-rails example project codereferences/EXAMPLE-ruby.md- ruby example project codereferences/EXAMPLE-android.md- android example project codereferences/EXAMPLE-swift.md- swift example project codereferences/EXAMPLE-react-native.md- react-native example project codereferences/EXAMPLE-expo.md- expo example project codereferences/next-js.md- Next.js - docsreferences/react-router-v6.md- React router v6 - docsreferences/react-router-v7-framework-mode.md- React router v7 framework mode (remix v3) - docsreferences/react-router-v7-data-mode.md- React router v7 data mode - docsreferences/react-router-v7-declarative-mode.md- React router v7 declarative mode - docsreferences/nuxt-js-3-6.md- Nuxt.js (v3.0 to v3.6) - docsreferences/nuxt-js.md- Nuxt.js - docsreferences/vue-js.md- Vue.js - docsreferences/tanstack-start.md- Tanstack start - docsreferences/svelte.md- Svelte - docsreferences/astro.md- Astro - docsreferences/angular.md- Angular - docsreferences/django.md- Django - docsreferences/flask.md- Flask - docsreferences/python.md- Python - docsreferences/posthog-python.md- PostHog python SDKreferences/laravel.md- Laravel - docsreferences/ruby-on-rails.md- Ruby on rails - docsreferences/ruby.md- Ruby - docsreferences/android.md- Android - docsreferences/ios.md- Ios - docsreferences/react-native.md- React native - docsreferences/identify-users.md- Identify users - docs
Each framework reference contains SDK-specific installation, initialization, and usage patterns. Find the one matching the user's stack.
Key principles
- Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
- Minimal changes: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
- Match the docs: Follow the framework reference's initialization and capture patterns exactly.
How to use instrument-product-analytics on Cursor
AI-first code editor with Composer
Prerequisites
Before installing skills in Cursor, ensure your development environment meets these requirements:
- ›Cursor installed and configured on your development machine
- ›Node.js version 16.0+ with npm package manager (verify with
node --version) - ›Active project directory or workspace where you want to add instrument-product-analytics
Execute installation command
Execute the skills CLI command in your project's root directory to begin installation:
The skills CLI fetches instrument-product-analytics from GitHub repository PostHog/skills and configures it for Cursor.
Select Cursor when prompted
The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:
Verify installation
Confirm successful installation by checking the skill directory location:
Reload or restart Cursor to activate instrument-product-analytics. Access the skill through slash commands (e.g., /instrument-product-analytics) or your agent's skill management interface.
Security & Verification Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.
List & Monetize Your Skill
Submit your Claude Code skill and start earning
Use Cases▌
Task Automation & Efficiency
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Knowledge Enhancement
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Quality Improvement
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
Implementation Guide▌
Prerequisites
- ›Claude Desktop or compatible AI client with skill support
- ›Clear understanding of task or problem to solve
- ›Willingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Installation Steps
- 1.Install skill using provided installation command
- 2.Test with simple use case relevant to your work
- 3.Evaluate output quality and relevance
- 4.Iterate on prompts to improve results
- 5.Integrate into regular workflow if valuable
Common Pitfalls
- ⚠Expecting perfect results without iteration
- ⚠Not providing enough context in prompts
- ⚠Using skill for tasks outside its intended scope
- ⚠Accepting outputs without review and validation
Best Practices▌
✓ Do
- +Start with clear, specific prompts
- +Provide relevant context and constraints
- +Review and refine all outputs before using
- +Iterate to improve output quality
- +Document successful prompt patterns
✗ Don't
- −Don't use without understanding skill limitations
- −Don't skip validation of outputs
- −Don't share sensitive information in prompts
- −Don't expect skill to replace human judgment
💡 Pro Tips
- ★Be specific about desired format and style
- ★Ask for multiple options to choose from
- ★Request explanations to understand reasoning
- ★Combine AI efficiency with human expertise
When to Use This▌
✓ Use When
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid When
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path▌
- 1Familiarize yourself with skill capabilities and limitations
- 2Start with low-risk, non-critical tasks
- 3Progress to more complex and valuable use cases
- 4Build expertise through regular use and experimentation
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.5★★★★★73 reviews- ★★★★★Kaira Rahman· Dec 20, 2024
Keeps context tight: instrument-product-analytics is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Hana Khanna· Dec 16, 2024
Registry listing for instrument-product-analytics matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Ama Ramirez· Dec 12, 2024
Useful defaults in instrument-product-analytics — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Pratham Ware· Dec 8, 2024
instrument-product-analytics fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Hana Malhotra· Dec 8, 2024
instrument-product-analytics is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Chinedu Mensah· Dec 8, 2024
instrument-product-analytics fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Soo Gill· Dec 4, 2024
I recommend instrument-product-analytics for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Henry Chen· Dec 4, 2024
instrument-product-analytics fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Benjamin Taylor· Nov 27, 2024
instrument-product-analytics reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Benjamin Johnson· Nov 23, 2024
Solid pick for teams standardizing on skills: instrument-product-analytics is focused, and the summary matches what you get after install.
showing 1-10 of 73