GithubHelp home page GithubHelp logo

javascriptbach / react-router-ga Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fed/react-router-ga

0.0 1.0 0.0 868 KB

Google Analytics component for React Router

Home Page: https://npm.im/react-router-ga

License: MIT License

JavaScript 93.38% CSS 6.62%

react-router-ga's Introduction

react-router-ga

Downloads Version License

Google Analytics component for React Router. Bear in mind this is a super simple implementation that only logs page views. Logging of custom events, exceptions, user timings or social interactions is currently not supported.

Props

Prop Type Description Default value
id string Google Analytics tracking ID Required
basename string If provided, react-router-ga will prepend the basename to the pathname of each page view. (This should match the basename provided to the React Router BrowserRouter component. See here for documentation.) -
debug boolean If enabled, react-router-ga will log all page views to the console false
trackPathnameOnly boolean If enabled, react-router-ga will only send page views when the pathname changed false

Usage Example

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import Analytics from 'react-router-ga';
import { Home, Login, NoMatch } from './components';

ReactDOM.render(
  <BrowserRouter>
    <Analytics id="UA-123456789-0" debug>
      <Switch>
        <Route exact path="/" component={Home}/>
        <Route exact path="/login" component={Login} />
        <Route component={NoMatch} />
      </Switch>
    </Analytics>
  </BrowserRouter>,
  document.getElementById('root')
);

Demo App

You can also have a look at the demo app in the example directory. This app is bootstrapped with create-react-app and is making use of both react-router and react-router-ga.

Probably the code sample you are looking for is in the example/src/index.js file.

Dependencies

This project has react@^16.0.0 and react-router-dom@^4.0.0 as peer dependencies.

react-router-ga's People

Contributors

fed avatar alexyuly avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.