HOC for adding google analytics to component
This project uses node and npm.
$ npm install react-with-ga
$ # OR
$ yarn add react-with-ga
import React, { Component } from "react";
import ReactDOM from "react-dom";
import withGA from "react-with-ga";
import "./styles.css";
withGA.setConfig({
trackingID: "UA-000000-01"
});
class Temp extends Component {
componentDidMount() {
// https://www.npmjs.com/package/react-ga
console.log(this.props.ga); // Object {initialize: function initialize(), ga: function ga(), set: function set(), send: function send(), pageview: function pageview()…}
}
render() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
}
const rootElement = document.getElementById("root");
const App = withGA(Temp);
ReactDOM.render(<App />, rootElement);
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
MIT