🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

react-mixpanel-browser

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mixpanel-browser

React providers for mixpanel-browser using the Context API.

3.2.2
npm
Version published
Weekly downloads
2.6K
-42.62%
Maintainers
1
Weekly downloads
 
Created
Source

react-mixpanel-browser

Wrapper of mixpanel-browser for use in React apps.

Provides a MixpanelLib instance via the context API.

Installation

Install the package using NPM or Yarn:

    npm install --save react-mixpanel-browser
    # or
    # yarn add react-mixpanel-browser

Add your Mixpanel token to ./.env:

    REACT_APP_MIXPANEL_TOKEN=<token>

Usage

MixpanelProvider Component

import React from 'react';
import { MixpanelProvider } from 'react-mixpanel-browser';

const App = (props) => (
  <MixpanelProvider>
    ...
  </MixpanelProvider>
);

export default App;

useMixpanel Hook

import React from 'react';
import { useMixpanel } from 'react-mixpanel-browser';

const Dashboard = (props) => {

  const mixpanel = useMixpanel();

  if (mixpanel.config.token) { // Check that a token was provided (useful if you have environments without Mixpanel)
    mixpanel.track('My Event', {
      my_custom_prop: 'foo',
    });
  }

  return (
    <>
      ...
    </>
  );

};

export default Dashboard;

withMixpanel High-Order Component

import React, { Component } from 'react';
import { withMixpanel } from 'react-mixpanel-browser';

class Dashboard extends Component {

  render() {

    const { mixpanel } = this.props;

    if (mixpanel.config.token) { // Check that a token was provided (useful if you have environments without Mixpanel)
      mixpanel.track('My Event', {
        my_custom_prop: 'foo',
      });
    }

    return (
      <>
        ...
      </>
    );

  }

}

export default withMixpanel(Dashboard);

Keywords

react

FAQs

Package last updated on 16 Jan 2022

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