Skip to main content
skill CX Codex

integration-javascript_web — Claude Code skill: setup and usage

integration-javascript_web guides client-side PostHog setup in browser JavaScript apps using posthog-js.

MIT 125 installs ★ 80 updated 2026-10-24

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PostHog/skills --skill integration-javascript_web -a claude-code
Open on GitHub

What integration-javascript_web does

This skill directs the integration through four distinct stages: begin, edit, revise, and conclude. It enforces standard client patterns: keeping PostHog credentials in environment variables, preserving default autocapture for forms and clicks, and executing posthog.init() before invoking other SDK calls.

The library runs strictly in web browsers. Server execution will fail, because backend JavaScript requires posthog-node. When a backend exists, the skill instructs passing X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers to align tracking across stacks.

Personal data handling follows a strict boundary. Sensitive user fields belong solely in posthog.identify(), keeping them entirely out of posthog.capture() event payloads. It also sets up posthog.reset() on logout to unlink subsequent events.

What it helps with

  • embed posthog-js into a client-side JavaScript project
  • set up user identification on login and page refreshes
  • pass session and distinct IDs to the backend via headers
  • add PostHog error monitoring around API calls

Example prompts for the agent

  • Add PostHog tracking to this web app using posthog-js
  • Implement posthog.identify on user authentication and posthog.reset on logout
  • Set up error tracking with PostHog around the main API endpoints

How to install integration-javascript_web

1Skills CLI (Vercel)

npx skills add PostHog/skills --skill integration-javascript_web -a claude-code

2Manually: put the files in place

~/.claude/skills/integration-javascript_web/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/integration-javascript_web/

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

Questions about integration-javascript_web

How to install integration-javascript_web in Claude Code?

Run npx skills add PostHog/skills --skill integration-javascript_web -a claude-code in your terminal.

What does integration-javascript_web do?

It provides workflow steps and strict rules for embedding PostHog browser analytics into web frontends.

Can posthog-js be imported into Node.js backend files?

No, posthog-js is browser-only. Server environments require the posthog-node package instead.

Source text

SKILL.md · MIT
---
name: integration-javascript_web
description: >-
  PostHog integration for client-side web JavaScript applications using
  posthog-js
metadata:
  author: PostHog
  version: 1.9.4
---

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

© PostHog · MIT · PostHog/skills

Similar skills

All skills for Frontend and UI →

From the same set112

The whole set →
account-handover account-handover drafts structured handover briefings when transferring PostHog accounts between TAMs or CSMs. CX Codex +1 193installs feature-flags-nextjs feature-flags-nextjs puts PostHog feature flags into a Next.js app: checks inside components, evaluation on the server, and flag management from chat when the PostHog MCP server is connected. CX Codex +1 140installs writing-simplified-technical-english writing-simplified-technical-english rewrites English prose to the ASD-STE100 controlled-language standard: one meaning per word, active voice, short sentences. Built for reports, PR descriptions and prompts. CX Codex +1 138installs integration-javascript_node integration-javascript_node adds PostHog analytics to a server-side Node.js app with posthog-node: events in route handlers, user identification, exception tracking. CX Codex +1 131installs llm-analytics-setup llm-analytics-setup adds PostHog LLM analytics to an app running on any supported provider, tracking tokens, latency and cost for every generation. CX Codex +1 120installs experiment-audit The experiment-audit Claude Code skill checks a PostHog experiment's setup, variant data, attribution, and metrics. It runs on requests to review or validate an A/B test. CX Codex +1 118installs error-tracking-web error-tracking-web adds PostHog error tracking to a JavaScript web app: exception capture, source maps, alerts and issue triage, with the agent editing your code. CX Codex +1 116installs monthly-to-annual The monthly-to-annual Claude Code skill evaluates a PostHog customer’s move from monthly billing to an annual prepaid credit plan. It produces a discount briefing and a plain-text Slack draft. CX Codex +1 115installs

Project sponsors

Companies that keep this analytics open