2.0.4 • Published 5 years ago

ornament-react-analytics v2.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

React Google Analytics Build Status

React component to work with Google analytics

Install

npm install ornament-react-analytics

This module targets Node.js 8 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers use Babel compiler.

Usage

You need to connect google analytics script by yourself. For example you can simply include script tag

<script src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX"></script>

React application

const { Provider, withTrack, useTrack } = require('ornament-react-analytics');


const TrackButtonHOC = withTrack((props) => (
  <button onClick={() => props.track()}>Track</button>
));

const TrackButtonHook = () => {
  const track = useTrack();
  return <button onClick={() => track()}>Track</button>;
};

const App = () => (
  // Every time location property is changed, pageview event is sent
  <Provider id="UA-XXXXX" location={currentPageUrl} dataLayer={window.dataLayer}>
    <TrackButtonHOC />
    <TrackButtonHook />
  </Provider>
);

License

MIT © Abylay Keldibek

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago