1.6.0 • Published 2 months ago

mixpanel-lite v1.6.0

Weekly downloads
30
License
MIT
Repository
github
Last release
2 months ago

mixpanel-lite

Build Status

A lightweight (2.9k) alternative to mixpanel-js with offline support for Hybrid and Progressive Web Apps.

Events are written to localStorage first and are only removed once the Mixpanel HTTP API confirms receipt, thus allowing the device to go offline without losing events.

Usage

Add mixpanel-lite.min.js to your project:

<script src="mixpanel-lite.min.js"></script>

At present only the following methods are supported:

// setup mixpanel
mixpanel.init('your-token-here'); // pass { mute: true } to mute by default

// assign all future events to a user
mixpanel.identify('user@email.com');

// register 'Gender' as a super property
mixpanel.register({'Gender': 'Female'});

// assign user info
mixpanel.people.set({
    $email: 'user@email.com' // only special properties need the $
});

// track an event
mixpanel.track('Your Event Name' {
    firstName: 'Optional event property 1',
    lastName: 'Optional event property 2'
});

// get super property
mixpanel.getProperty('distinct_id');

// clear current identity
mixpanel.reset();

// stop sending data to mixpanel (calls to track, identify etc are ignored)
mixpanel.mute();

// resume sending data to mixpanel
mixpanel.unmute();

// check if mixpanel is muted
if (mixpanel.muted) {
    console.log('Mixpanel is disabled');
}

Additional tracking properties

mixpanel-lite adds additional properties to each tracking event:

NameTypeDescription
offlinebooleantrue if event captured when offline
automatedbooleantrue if event captured using an automated browser
devbooleantrue if event captured when running locally
adobjectobject containing online ad click ids
utmobjectobject containing UTM tracking values
botbooleantrue if script executing via a bot request

Contributing

Pull requests are welcomed:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Dependencies

mixpanel-lite uses window.localStorage and window.Promise which should exist in all modern browsers.

Update .min files

To generate a new mixpanel-lite.min.js from source, tweak the version number in package.json and run:

npm run build

Star the repo

Star the repo if you find this useful as it helps me prioritize which bugs I should tackle first.

History

For change-log, check releases.

License

Licensed under MIT License © John Doherty

1.6.0

2 months ago

1.5.9

2 months ago

1.5.5

2 years ago

1.5.6

2 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.4.3

3 years ago

1.3.4

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.3.3

3 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago