2.61.2 • Published 7 months ago

mixpanel-browser v2.61.2

Weekly downloads
181,659
License
Apache-2.0
Repository
github
Last release
7 months ago

Mixpanel JavaScript Library

Build Status npm.io

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 bundle asynchronously (via script tag):

import mixpanel from 'mixpanel-browser/src/loaders/loader-module-with-async-recorder';

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:3000/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 at doc/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

fundwave-fund-management@do-killer/dodo-wallet2minsilo-react-client@sellics/profit@sellics/react-trackinger-prism-web@datatoggle/datatoggle-mixpanel@fast-af/analyticsmn-reveal-worker-test@airstudio/extensionshahnbee-test-client@infinitebrahmanuniverse/nolb-mix@everything-registry/sub-chunk-2179pw-testmsg-odds-summary-femsg-odds-summary-fe-test-1polygona-3d-clienttalentorg-profile-editortableau-add-invue-mixpanelvue-mixpanel-browservue-npm-publish@peachy-studio/client-portal@peculiar/identityfront-scannerjeffreykarimaaitbbajoplin-plugin-wakatimejs-qslatticeflow-widgetslandrinfront-event-analyticshookedjsherlhay-helpershealthnexus-utils-uihealthtap-ai-rrhealthtap-ai-rr-devhelp-client-testhelx-analyticsinyad-design-system-kintegrateskite-helpers-test@wavo-cloud/auth@xfers/xfers-js-sdk@thoughtspot/visual-embed-sdk@tresinternet/vue3-mixpanel@verityguard/emblem-sdk-client@vroskus/library-mixpanel@useblu/blu-lytics@utilitywarehouse/customer-help-tracking-core@utilitywarehouse/customer-help-tracking-for-browser@utilitywarehouse/customer-tracking-for-browser@venture-allaboutme/consent-manager@xylabs/react-mixpanel@xtreamsrl/react-analytics-mixpanel@xyo-network/react-user-events@zalastax/nolb-mix@zamp/acceptanceanalytics_adapterall-caps@zuludmmswap/interfacealfred-client-appastro-parent-componentsastro-parent-portal-testastrosafe-parent-portal-componentsashish-sdk@circulare/usage-tracker-browser@9amhealth/webcomponents3d-viewer-package-new4r-landing-page@haptik/helpers@cognite/3d-viewer@cognite/copilot-core@cognite/reveal@credenza-web3/passport@collabland/lifi-widget@olaisaac/event-dispatcher-sdkstream-engine-playerui-test-rowflex@balena/jellyfish-ui-components@cleeng/mediastore-sdk-react-16@cleeng/mediastore-sdk@brandwatch/remimi@brainfish-ai/search-widgetunigraph-dev-explorer@h790/toibox-library@livelyapp/chatui@localazy/components@local-logic/core@logcomex/shared-components@legalmentedev/capacitor-mixpanel@libhub/utils@moser-inc/moser-labs-react@newtonschool/ns-events-library@ngvip/analytics@near-wallet/frontend@neon.id/context@portxchange/mixpanel-utils@ristek-kit/ads@ringcentral-integration/commons@pangolindex/components
2.56.0-ac-alpha-3

10 months ago

2.57.1

10 months ago

2.59.0

9 months ago

2.60.0

9 months ago

2.56.0

11 months ago

2.58.0

10 months ago

2.61.0

8 months ago

2.61.1

7 months ago

2.61.2

7 months ago

2.55.1

1 year ago

2.53.0

1 year ago

2.55.0

1 year ago

2.51.0

1 year ago

2.54.0

1 year ago

2.54.1

1 year ago

2.52.0

1 year ago

2.50.0

1 year ago

2.49.0

2 years ago

2.48.0

2 years ago

2.48.1

2 years ago

2.47.0

2 years ago

2.46.0

3 years ago

2.43.0

4 years ago

2.45.0

4 years ago

2.42.1

4 years ago

2.42.0

4 years ago

2.41.0

5 years ago

2.40.1

5 years ago

2.40.0

5 years ago

2.39.0

5 years ago

2.38.0

5 years ago

2.37.0

5 years ago

2.36.0

5 years ago

2.35.0

6 years ago

2.34.0

6 years ago

2.33.1

6 years ago

2.33.0

6 years ago

2.32.0

6 years ago

2.31.0

6 years ago

2.30.1

6 years ago

2.29.1

6 years ago

2.29.0

6 years ago

2.28.0

6 years ago

2.27.1

7 years ago

2.27.0

7 years ago

2.26.0

7 years ago

2.25.0

7 years ago

2.24.0

7 years ago

2.23.0

7 years ago

2.23.0-beta

7 years ago

2.22.4

7 years ago

2.22.3

7 years ago

2.22.2

7 years ago

2.22.1

7 years ago

2.22.0

7 years ago

2.21.0

7 years ago

2.20.0

8 years ago

2.19.0

8 years ago

2.18.0

8 years ago

2.17.1

8 years ago

2.17.0

8 years ago

2.16.0

8 years ago

2.15.0

8 years ago

2.14.0

8 years ago

2.13.0

8 years ago

2.11.1

9 years ago

2.11.0

9 years ago

2.10.0

9 years ago

2.9.17

9 years ago

2.9.16

9 years ago

2.9.15

9 years ago

2.9.14

9 years ago

2.9.12

9 years ago

2.9.9

9 years ago

2.9.8

9 years ago

2.9.6

9 years ago

2.8.1

9 years ago

2.8.0

9 years ago

2.7.2

10 years ago

2.7.0

10 years ago