/react-with-ga

HOC for adding google analytics to component

Primary LanguageJavaScriptMIT LicenseMIT

react-with-ga

package version package downloads standard-readme compliant package license make a pull request

HOC for adding google analytics to component

Table of Contents

Install

This project uses node and npm.

$ npm install react-with-ga
$ # OR
$ yarn add react-with-ga

Usage

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);

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT