Skip to main content
skill CX Codex

integration-javascript_node — Claude Code skill: PostHog for Node.js

integration-javascript_node adds PostHog analytics to a server-side Node.js app with posthog-node: events in route handlers, user identification, exception tracking.

MIT 131 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_node -a claude-code
Open on GitHub

What integration-javascript_node does

The skill walks an agent through wiring PostHog into a server-side Node.js app. Four step files carry the work in order: basic-integration-1.0-begin.md, basic-integration-1.1-edit.md, basic-integration-1.2-revise.md, basic-integration-1.3-conclude.md. Reference notes on Node.js, the posthog-node SDK and user identification sit next to an example project the agent is told to imitate.

Expect edits like these: a posthog.capture() call in every route that writes data, captureException(err, distinctId) inside the framework's error handler, and enableExceptionAutocapture: true in the client options. Keys stay in environment variables. Code that already integrates something else is left alone.

Server code needs posthog-node. The browser package posthog-js won't do the job here. Long-running servers batch events on their own, so flush settings should stay untouched. CLIs, scripts and serverless functions get flushAt: 1 and flushInterval: 0 so events go out right away. A reverse proxy is not part of this setup — ad blockers only matter for client-side JavaScript. Build and type checks are read from package.json scripts.

What it helps with

  • track signup and login events in a Node.js backend
  • send exceptions from an Express or Fastify error handler to PostHog
  • keep PostHog API keys out of the source code
  • flush events from a short-lived CLI or serverless function
  • correlate browser sessions with server-side events through headers

Example prompts for the agent

  • Add PostHog to our Express server with posthog-node and read the key from an environment variable.
  • Turn on enableExceptionAutocapture and put captureException in the error handler.
  • Run the skill steps, starting at basic-integration-1.0-begin.md and finishing with basic-integration-1.3-conclude.md.

How to install integration-javascript_node

1Skills CLI (Vercel)

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

2Manually: put the files in place

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

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

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

Questions about integration-javascript_node

How do I install integration-javascript_node in Claude Code?

Run npx skills add PostHog/skills --skill integration-javascript_node -a claude-code. The skill lands in ~/.claude/skills/integration-javascript_node/SKILL.md.

What does integration-javascript_node do?

It connects PostHog analytics to a server-side Node.js app: events in route handlers, identification on login and signup, and exception capture in the error handler.

Do I need a reverse proxy for server-side PostHog?

No. A proxy helps browser JavaScript get around ad blockers. Node.js servers send events directly.

Source text

SKILL.md · MIT
---
name: integration-javascript_node
description: PostHog integration for server-side Node.js applications using posthog-node
metadata:
  author: PostHog
  version: 1.9.4
---

# PostHog integration for JavaScript Node

This skill helps you add PostHog analytics to JavaScript Node 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/node.md` - Node.js - docs
- `references/posthog-node.md` - PostHog Node.js 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

- posthog-node is the Node.js server-side SDK package name – do NOT use posthog-js on the server
- Include enableExceptionAutocapture: true in the PostHog constructor options
- Add posthog.capture() calls in route handlers for meaningful user actions – every route that creates, updates, or deletes data should track an event with contextual properties
- Add posthog.captureException(err, distinctId) in the application's error handler (e.g., Express error middleware, Fastify setErrorHandler, Koa app.on('error'))
- In long-running servers, the SDK batches events automatically – do NOT set flushAt or flushInterval unless you have a specific reason to
- For short-lived processes (scripts, CLIs, serverless), set flushAt to 1 and flushInterval to 0 to send events immediately
- Reverse proxy is NOT needed for server-side Node.js – only client-side JavaScript needs a proxy to avoid ad blockers
- Remember that source code is available in the node_modules directory
- Check package.json for type checking or build scripts to validate changes

## 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 Backend and APIs →

From the same set112

The whole set →
posthog-pls-transition-leads posthog-pls-transition-leads sorts PostHog product-led leads that are about to meet a real bill, then writes the first outreach email. Built for TAEs working startup rolloffs and high first invoices. CX Codex +1 199installs 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_web integration-javascript_web guides client-side PostHog setup in browser JavaScript apps using posthog-js. CX Codex +1 125installs 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

Project sponsors

Companies that keep this analytics open