Skip to content

Google Analytics for React apps with ease.

License

Notifications You must be signed in to change notification settings

rammoozz/react-with-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-with-analytics

npm version

Installation

yarn add react-ga react-with-analytics

Usage

With react-router

import React from 'react';

import {
  BrowserRouter,
  Link,
  Route,
  Switch,
  withRouter
} from 'react-router-dom';

import withAnalytics, { initAnalytics } from 'react-with-analytics';

initAnalytics('UA-00000000-0');

const Home = () => (
  <div>
    HOME <Link to="/about">ABOUT</Link>
  </div>
);

const About = () => (
  <div>
    ABOUT <Link to="/">HOME</Link>
  </div>
);

const Root = () => (
  <Switch>
    <Route exact path="/" component={Home} />
    <Route path="/about" component={About} />
  </Switch>
);

// you should only use `withAnalytics` once to warp your whole app
const App = withRouter(withAnalytics(Root));

const AppWithRouter = () => (
  <BrowserRouter>
    <App />
  </BrowserRouter>
);

export default AppWithRouter;

Tracking users and events

import { trackUser, trackEvent } from 'react-with-analytics';

// you can use these anywhere in your app
trackUser('@username');
trackEvent('Editing', 'Deleted Component', 'Game Widget');

About

Google Analytics for React apps with ease.

Resources

License

Stars

Watchers

Forks

Packages

No packages published