Generated banner for Integration Javascript Web
Generated logo for Integration Javascript Web

Integration Javascript Web

PostHogOfficialCreated by PostHog

  • Skill
  • Tool integration
  • Data and AI
  • MIT
  • No issues found

From the author

PostHog integration for client-side web JavaScript applications using posthog-js
— the description by PostHog

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a systematic, four-phase workflow for developers to integrate PostHog analytics into JavaScript web applications. It emphasizes best practices such as using environment variables for configuration, maintaining minimal code changes, and ensuring proper user identification and error tracking. The skill guides the user through planning event tracking, implementing capture calls, revising the implementation, and concluding the setup, while strictly adhering to data privacy guidelines regarding PII.

What it does

  • Provides a step-by-step procedure for setting up PostHog in web projects.
  • Guides the creation of an event tracking plan via a JSON configuration file.
  • Ensures correct implementation of user identification and session management.
  • Directs the addition of error tracking at critical application boundaries.
  • Enforces security best practices like avoiding hardcoded keys and PII in event properties.
  • Facilitates correlation between client-side and server-side event data.

When to use it

  • When you need to add PostHog analytics to a new or existing JavaScript web application.
  • When you want to ensure your analytics implementation follows standard industry patterns.
  • When you need to track user behavior across both client-side and server-side environments.
  • When you need to implement robust error tracking alongside standard event capture.

Advantages

  • Promotes consistent and maintainable analytics code across the project.
  • Reduces the risk of exposing sensitive user data (PII) in event properties.
  • Ensures critical business events are captured on both client and server sides.
  • Provides a clear, repeatable process for scaling analytics coverage.

Usage examples

“Integrate PostHog into my React web application.”
The agent will initiate the four-phase workflow, starting with an analysis of your project structure to create a .posthog-events.json plan before implementing the tracking code.
“How do I identify users in my PostHog setup?”
The agent will guide you to use posthog.identify() during login and signup, ensuring you pass the correct user properties while maintaining session correlation.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/posthog/integration-javascript-web/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip integration-javascript-web.zip -d .agents/skills

Documentation by PostHog

PostHog integration for JavaScript Web

This skill helps you add PostHog analytics to JavaScript Web applications.

Workflow

Follow these steps in order to complete the integration:

  1. basic-integration-1.0-begin.md - PostHog Setup - Begin ← Start here

  2. basic-integration-1.1-edit.md - PostHog Setup - Edit

  3. basic-integration-1.2-revise.md - PostHog Setup - Revise

  4. basic-integration-1.3-conclude.md - PostHog Setup - Conclusion

Reference files

  • references/js.md - JavaScript web - docs

  • references/posthog-js.md - PostHog JavaScript web SDK

  • references/identify-users.md - Identify users - docs

  • references/basic-integration-1.0-begin.md - PostHog setup - begin

  • references/basic-integration-1.1-edit.md - PostHog setup - edit

  • references/basic-integration-1.2-revise.md - PostHog setup - revise

  • references/basic-integration-1.3-conclude.md - PostHog setup - conclusion

The example project shows the target implementation pattern. Consult the documentation for API details.

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 example: Your implementation should follow the example project's patterns as closely as possible.

Framework guidelines

  • Remember that source code is available in the node_modules directory

  • Check package.json for type checking or build scripts to validate changes

  • posthog-js is the JavaScript SDK package name

  • posthog.init() MUST be called before any other PostHog methods (capture, identify, etc.)

  • posthog-js is browser-only — do NOT import it in Node.js or server-side contexts (use posthog-node instead)

  • Autocapture is ON by default with posthog-js (tracks clicks, form submissions, pageviews). Do NOT disable autocapture unless the user explicitly requests it.

  • NEVER send PII in posthog.capture() event properties — no emails, full names, phone numbers, physical addresses, IP addresses, or user-generated content

  • PII belongs in posthog.identify() person properties (email, name, role), NOT in capture() event properties

  • Call posthog.identify(userId, { email, name, role }) on login AND on page refresh if the user is already logged in

  • Call posthog.reset() on logout to unlink future events from the current user

  • For SPAs without a framework router, capture pageviews with posthog.capture($pageview) or use the capture_pageview history_change option in init for History API routing

Identifying users

Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers to maintain correlation.

Error tracking

Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.

Files

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Node.js

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
PostHog
Publisher
PostHog (Official)
Source
PostHog/skills · skills/posthog/integration/skills/javascript_web · commit a5d30e7
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
PostHog/skills

AutoGineer is not affiliated with or endorsed by PostHog.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download integration-javascript-web.zip