JavaScript analytics libraries

Updated Nov 2026

JavaScript analytics libraries collect events from web applications for analysis. An SDK records page views, clicks, and custom events in the browser before it sends them to an analytics service. These libraries supply the usage data behind product dashboards, funnels, and A/B test results.

Popularity

PostHog has the most monthly downloads in this comparison, at 95.9M.

LibraryMonthly downloadsStarsLast releaseLicense
PostHog
95.9M
645Nov 2026(Apache-2.0 AND MIT)
Google Analytics for Firebase
54.2M
5.2KNov 2026Apache-2.0
Vercel Web Analytics
41.8M
520Mar 2026MIT
Mixpanel
14.2M
944Nov 2026Apache-2.0
Amplitude Browser SDK
13.9M
181Nov 2026MIT
Segment Analytics.js
10.2M
481Nov 2026MIT
RudderStack JavaScript SDK
3.0M
181Nov 2026MIT
Snowplow Browser Tracker
2.6M
594Nov 2026BSD-3-Clause
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Captures browser behavior and custom events for PostHog analytics.

Downloads / mo
95.9M
Stars
645
Last release
1.450.1
License
(Apache-2.0 AND MIT)

Strengths

  • Captures browser interactions automatically. Collect supported page, click, input-change, and form-submission events.
  • Associates events with signed-in users. Connect identified events across sessions, devices, and platforms.

Limitations

  • Form values need explicit properties. Add custom properties when form-submission events need business-specific values.
  • SDK extensions need network access. Allow required extension and ingestion hosts under the application content security policy.

Quickstart

From PostHog docs
$ npm install posthog-js@1
import posthog from 'posthog-js'

posthog.init('<ph_project_token>', {
  api_host: 'https://us.i.posthog.com',
  defaults: '2026-08-30'
})

posthog.capture('user_signed_up');

Google Analytics for Firebase

Sends Google Analytics events from a Firebase web app with logEvent.

Downloads / mo
54.2M
Stars
5.2K
Last release
0.10.26
License
Apache-2.0

Quickstart

From Firebase docs
$ npm install firebase
import { initializeApp } from "firebase/app";
  import { getAnalytics } from "firebase/analytics";

  // TODO: Replace the following with your app's Firebase project configuration
  // See: https://firebase.google.com/docs/web/learn-more#config-object
  const firebaseConfig = {
      // ...
  };

  // Initialize Firebase
  const app = initializeApp(firebaseConfig);

  
  // Initialize Analytics and get a reference to the service
  const analytics = getAnalytics(app);

Google Analytics for Firebase examples

From open-source projects on GitHub

Vercel Web Analytics

Tracks custom events for Vercel Web Analytics through its track() function.

Downloads / mo
41.8M
Stars
520
Last release
2.0.1
License
MIT

Quickstart

From Vercel docs
$ npm install @vercel/analytics
import { inject } from '@vercel/analytics';

inject();

Vercel Web Analytics examples

From open-source projects on GitHub

Sends browser events and user properties to Mixpanel projects.

Downloads / mo
14.2M
Stars
944
Last release
2.86.0
License
Apache-2.0

Strengths

  • Supports automatic interaction capture. Enable autocapture to collect supported browser events.
  • Transforms events before sending. Use hooks to modify or drop data before transmission.

Limitations

  • Default bundle includes replay code. Choose the core loader when session recording is unnecessary.
  • Regional projects need matching hosts. Set the correct regional ingestion host or events will be dropped.

Quickstart

From README.md
$ npm install --save mixpanel-browser
import mixpanel from 'mixpanel-browser';

mixpanel.init("YOUR_TOKEN", {autocapture: true});
mixpanel.track("An event");

Mixpanel examples

From open-source projects on GitHub

Amplitude Browser SDK

Sends browser analytics events and identity updates to Amplitude.

Downloads / mo
13.9M
Stars
181
Last release
2.49.3
License
MIT

Strengths

  • Configures automatic event capture. Choose which supported events the SDK collects automatically.
  • Extends processing through plugins. Add before, enrichment, and destination plugins to the event pipeline.

Limitations

  • Replay needs an additional package. Use the Unified SDK when the application also needs session replay.
  • Remote settings override local options. Account for project-level remote configuration when controlling autocapture features.

Quickstart

From README.md
$ npm install @amplitude/analytics-browser
import * as amplitude from '@amplitude/analytics-browser';

amplitude.init('<YOUR_API_KEY>');

amplitude.track('Page Viewed');

Segment Analytics.js

Sends browser analytics events to configured destination tools.

Downloads / mo
10.2M
Stars
481
Last release
1.84.4
License
MIT

Strengths

  • Routes events to destination tools. Use a common tracking API across configured destinations.
  • Can defer network initialization. Buffer calls until the application explicitly loads the client.

Limitations

  • Load each client once. Reuse the initialized client instead of loading it repeatedly.

Quickstart

From README.md
$ npm install @segment/analytics-next
import { AnalyticsBrowser } from '@segment/analytics-next'

const analytics = AnalyticsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' })

analytics.identify('hello world')

document.body?.addEventListener('click', () => {
  analytics.track('document body clicked!')
})

Segment Analytics.js examples

From open-source projects on GitHub

RudderStack JavaScript SDK

Tracks browser events and sends them through RudderStack to configured destinations.

Downloads / mo
3.0M
Stars
181
Last release
3.36.1
License
MIT

Quickstart

From RudderStack docs
$ npm install @rudderstack/analytics-js
// Step 1: Install the SDK - `npm i @rudderstack/analytics-js`
// Step 2: Initalize the SDK
import { RudderAnalytics } from '@rudderstack/analytics-js';
const rudderAnalytics = new RudderAnalytics();
rudderAnalytics.load(process.env.WRITE_KEY, process.env.DATA_PLANE_URL, {});
// Q: How to generate your WRITE_KEY and DATA_PLANE_URL?
// A: Create a new JavaScript source at https://app.rudderstack.com
export { rudderAnalytics };
// Step 3: Call event tracking methods such as `page`, `track`, `identify`, etc. as needed
rudderAnalytics.page();
// NOTICE: This code works only if you have set up your browser-side code to use `npm` modules. Follow the quickstart guide otherwise.
// https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/quickstart/

RudderStack JavaScript SDK examples

From open-source projects on GitHub

Snowplow Browser Tracker

Adds Snowplow event tracking to a web application.

Downloads / mo
2.6M
Stars
594
Last release
4.10.3
License
BSD-3-Clause

Quickstart

From Snowplow docs
$ npm install @snowplow/browser-tracker
import { newTracker, trackPageView } from "@snowplow/browser-tracker";

newTracker('sp1', '{{collector_url}}', {
  appId: 'my-app-id',
  plugins: [ ],
})

trackPageView();

FAQ

Mixpanel changes or drops event data through hooks before sending it. Amplitude Browser SDK runs each event through before, enrichment, and destination plugins. Mixpanel's default bundle includes session replay code, while Amplitude adds replay through its Unified SDK.

PostHog captures supported page, click, input-change, and form-submission events automatically. Mixpanel collects supported browser events once autocapture is enabled.

PostHog captures supported page, click, input-change, and form-submission events. Amplitude Browser SDK lets each project choose which supported events it collects. Project-level remote settings in Amplitude can override those local options.

Both send events through one tracking API to configured destination tools. Segment Analytics.js can buffer calls until the application loads the client. RudderStack JavaScript SDK loads with a write key and a data plane URL that sets where events go.

No. Business-specific form values need custom properties added to the form-submission event.

For coding agents

Found your analytics library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official