Socket
Book a DemoInstallSign in
Socket

react-mixpanel

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mixpanel

Unofficial React bindings for Mixpanel

1.0.5
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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:

  • Import required modules:
import mixpanel from 'mixpanel-browser';
import { MixpanelProvider, MixpanelConsumer } from 'react-mixpanel';
  • Initialize your Mixpanel instance:
mixpanel.init("YOUR_TOKEN");
  • Render your app using MixpanelProvider:
ReactDOM.render(
    <MixpanelProvider mixpanel={mixpanel}>
        <App/>
    </MixpanelProvider>,
    document.getElementById('app')
);
  • 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.

FAQs

Package last updated on 06 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.