1.0.0 • Published 5 years ago

react-with-ga v1.0.0

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

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