
mixpanel-browser
The official Mixpanel JavaScript browser client library
About
The official Mixpanel JavaScript browser client library
Live mirror of the GitHub README. Updated whenever the repo's default branch changes.
Mixpanel JavaScript Library
The Mixpanel JavaScript Library is a set of methods attached to a global mixpanel object
intended to be used by websites wishing to send data to Mixpanel projects. A full reference
is available here.
Alternative installation via NPM
This library is available as a package on NPM (named mixpanel-browser to distinguish it from Mixpanel's server-side Node.js library, available on NPM as mixpanel). To install into a project using NPM with a front-end packager such as Vite or Webpack:
npm install --save mixpanel-browser
You can then import the lib:
import mixpanel from 'mixpanel-browser';
mixpanel.init("YOUR_TOKEN", {autocapture: true});
mixpanel.track("An event");
NOTE: the default mixpanel-browser bundle includes a bundled mixpanel-recorder SDK. We provide the following options to exclude mixpanel-recorder if you do not intend to use session replay or want to reduce bundle size:
To load the core SDK with no option of session recording:
import mixpanel from 'mixpanel-browser/src/loaders/loader-module-core';
To load the core SDK and optionally load session recording and targeting bundles asynchronously (via script tag):
import mixpanel from 'mixpanel-browser/src/loaders/loader-module-with-async-modules';
Use as a browser JavaScript module
If you are leveraging browser JavaScript modules, you can use importmap to pull in this library.
<script type="importmap">
{
"imports": {
"mixpanel-browser": "https://cdn.mxpnl.com/libs/mixpanel-js/dist/mixpanel.module.js"
}
}
</script>
<script type="module" src="main.js"></script>
Then you are free to import mixpanel-browser in your javascript modules.
// main.js
import mixpanel from 'mixpanel-browser';
mixpanel.init('YOUR_TOKEN', {autocapture: true, debug: true, persistence: 'localStorage'});
Building bundles for release
- Install development dependencies:
npm install - Build:
npm run build-dist
Running tests
- Install development dependencies:
npm install - Run unit tests:
npm test - Start test server for browser tests:
npm run integration_test - Browse to http://localhost:3001/tests/ and choose a scenario to run
In the future we plan to automate the last step with a headless browser to streamline development (although Mixpanel production releases are tested against a large matrix of browsers and operating systems).
Generating and publishing documentation
- Create bundled source build:
npm run build-dist - Generate Markdown:
npm run dox(result is atdoc/readme.io/javascript-full-api-reference.md) - Publish to readme.io via the rdme util:
RDME_API_KEY=<API_KEY> RDME_DOC_VERSION=<version> npm run dox-publish
Thanks
For patches and support: @bohanyang, @dehau, @drubin, @D1plo1d, @feychenie, @mogstad, @pfhayes, @sandorfr, @stefansedich, @gfx, @pkaminski, @austince, @danielbaker, @mkdai, @wolever, @dpraul, @chriszamierowski, @JoaoGomesTW, @@aliyalcinkaya, @chrisdeely, @dylan-asos, @chrisknu
Quick facts
npm install mixpanel-browserHow Sourcemap Explorer detects mixpanel-browser
We catch mixpanel-browser from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/mixpanel-browser/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.
- 1
Confirm the site exposes sourcemaps
In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment.
- 2
Find the package in the bundle
Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/mixpanel-browser/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/mixpanel-browser/package.json` gives you the exact installed version.
- 3
Read the version directly from package.json
Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/mixpanel-browser/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.
Recent versions
FAQ
What is mixpanel-browser used for?
The official Mixpanel JavaScript browser client library
How can I tell if a website is using mixpanel-browser?
Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `mixpanel-browser` from two complementary signals: `node_modules/mixpanel-browser/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.
What is the latest version of mixpanel-browser?
2.78.0, as published on the npm registry. The "Recent versions" table on this page lists the most recent 8 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.
Where can I read more?
Project homepage: https://github.com/mixpanel/mixpanel-js. Source code: https://github.com/mixpanel/mixpanel-js. Published on npm: https://www.npmjs.com/package/mixpanel-browser. Licensed as Apache-2.0.
Detected by Sourcemap Explorer
When a bundle ships sourcemaps, we read the embedded package.json for mixpanel-browser and report the precise version. Without sourcemaps, an import / require in the page's scripts is enough to flag it.