
posthog-js
https://github.com/posthog/posthog-js- Category
- Developer Tools
- Rank
- No. 375Tools index
- Pricing
- Open Source
- Type
- TOOL
- Builder
- posthog
- GitHub
- 603 stars
- Latest release
- posthog-react-native@4.68.0
- Date
About
Official PostHog JavaScript library. Send analytics events from any web app or site with autocapture support.
What it does
This repository houses a family of PostHog clients and integrations. Shared modules cover feature flags, error tracking, logs, metrics, surveys, compression, and persistence, while dedicated packages adapt those capabilities for browsers, servers, React, Next.js, and React Native.
Why it's ranked here
The project shows unusually broad platform coverage and a deliberate modular structure. Shared types and core behavior reduce fragmentation across clients. The main weakness is discoverability: the root documentation mostly lists packages and sends readers elsewhere for practical guidance.
What's good
The type surface is concrete and extensive, covering capture options, feature flags, session recording, configuration, logs, metrics, surveys, and request handling. Framework packages expose focused integration layers. Shared core modules centralize compression, tracing headers, error tracking, logging, metrics, cookies, and survey validation.
Tradeoffs
The repository is much larger than the browser package its name suggests, so contributors must navigate shared core code, framework adapters, plugins, and specialized integrations. The root documentation offers little installation or usage guidance. Repository development also expects pnpm and Node 24.
How to use it well
Pick the browser client when a web product already uses PostHog and needs typed access to its broader client features. Use the React, Next.js, server, or React Native packages when their dedicated integration matches your runtime. Source-map processing belongs to the separate build plugins and CLI workflow, not the browser client itself.
Technical notes+
The root package.json defines a private pnpm and Turbo monorepo with build, lint, unit, functional, end-to-end, packaging, public API, and tarball checks. packages/core/src/index.ts exports shared feature-flag, gzip, error-tracking, logging, metrics, cookie, tracing, survey, and core client surfaces. packages/types/src/index.ts centralizes public TypeScript contracts. packages/react/src/index.ts binds the default posthog-js instance before exporting context, hooks, components, and helpers. packages/next/src/index.ts exposes provider, server client creation, request-error capture, middleware, page-view tracking, hooks, and feature components. packages/plugin-utils/src/cli.ts constructs and launches PostHog CLI source-map processing, while packages/rollup-plugin/src/index.ts enables source maps and submits generated JavaScript chunks.
Observed
- Primary language
- TypeScript
- Repository structure
- Private pnpm monorepo orchestrated with Turbo
- Interface
- JavaScript and TypeScript library packages
- Platform support
- Packages target browsers, Node.js, React, Next.js, and React Native
- Build integration
- Includes Rollup and webpack plugin packages plus shared source-map CLI utilities
- Quality checks
- Root scripts cover linting, unit tests, functional tests, end-to-end tests, package tarballs, and public API checks
Read from README.md, package.json, packages/ai/src/index.ts, packages/mcp/src/index.ts, packages/web/src/index.ts, packages/core/src/index.ts, packages/next/src/index.ts, packages/react/src/index.ts, packages/types/src/index.ts, packages/plugin-utils/src/cli.ts, packages/plugin-utils/src/index.ts, packages/react-native/src/index.ts, packages/nextjs-config/src/index.ts, packages/rollup-plugin/src/index.ts, packages/browser-common/src/index.ts.
What it can do
Capture user interactions automatically
Web page elements and user events → Analytics events data
Send custom analytics events
Event data and properties → Tracked events in PostHog
Identify users
User ID and properties → User profile in analytics system
Track page views
Page navigation events → Page view analytics data
Capture form submissions
Form interaction data → Form analytics events
Record user sessions
User interactions and page events → Session replay data
Set user properties
User attributes and metadata → Updated user profiles
Tags
Tech Stack
Media

Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.