1.0.5 • Published 5 years ago

react-mixpanel v1.0.5

Weekly downloads
4,885
License
MIT
Repository
github
Last release
5 years ago

React Mixpanel

Build Status

The project provides simple wrapper over mixpanel-browser to ease using Mixpanel in your React app.

Usage

Install with: npm i react-mixpanel --save

Then use it like you would use Context API. In your root App.js:

  1. Import required modules:
import mixpanel from 'mixpanel-browser';
import { MixpanelProvider, MixpanelConsumer } from 'react-mixpanel';
  1. Initialize your Mixpanel instance:
mixpanel.init("YOUR_TOKEN");
  1. Render your app using MixpanelProvider:
ReactDOM.render(
    <MixpanelProvider mixpanel={mixpanel}>
        <App/>
    </MixpanelProvider>,
    document.getElementById('app')
);
  1. Then, everytime you'd like to use mixpanel you can get it using MixpanelConsumer:
const App = () => 
    <Foo>
        <MixpanelConsumer/>
            {mixpanel => ...}
        </MixpanelConsumer>
    </Foo>;

You can use mixpanel in lifecycle methods by passing it via prop!

class INeedMixpanel extends React.Component {
    componentDidMount() {
        this.props.mixpanel.track('Hello mixpanel!');
    }

    render() {
        return <div>Bar</div>;  
    }
}

const App = () => 
    <Foo>
        <MixpanelConsumer/>
            {mixpanel => <INeedMixpanel mixpanel={mixpanel}/>}
        </MixpanelConsumer>
    </Foo>;

Example

You can play with included example App in examples directory.

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

7 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.1

8 years ago