This helper file is based off of Andre Woons' wonderfully simple article, Setting up Mixpanel in React. I added some hacky type safety to the Mixpanel methods based on the official docs.
##Usage
- Copy Mixpanel.ts into your project directory, placing it wherever makes organizational sense (ex. in a helpers folder).
- Setup a Mixpanel account and copy your token into the
mixpanel.init('')
function in the Mixpanel.ts file. - Be sure you have node types installed; if not, run
npm i @types/node
to install. - Import
Mixpanel
in any of your components where you need to track an event. - Use
Mixpanel
as you would here: https://developer.mixpanel.com/docs/javascript - Optionally add any additional methods you need. I only included the Mixpanel methods I required.
MIT