# react-router-ga

> [![Downloads](https://img.shields.io/npm/dm/react-router-ga)](https://npm.im/react-router-ga) [![Version](https://img.shields.io/npm/v/react-router-ga)](https://npm.im/react-router-ga) [![License](https://img.shields.io/npm/l/react-router-ga)](https://ope

Latest version **1.2.3** (published 2020-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-router-ga
pnpm add react-router-ga
yarn add react-router-ga
bun add react-router-ga
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2020-03-05 |
| First published | 2017-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 72 |
| Author | Federico Knüssel |
| Maintainers | fknussel |
| Keywords | react-router-ga, react-router-dom, react-ga, analytics, react-analytics, react-router-analytics |

## Links

- npm: https://www.npmjs.com/package/react-router-ga
- Repository: https://github.com/fknussel/react-router-ga
- Homepage: https://github.com/fknussel/react-router-ga#readme
- Issues: https://github.com/fknussel/react-router-ga/issues
- npm.io page: https://npm.io/package/react-router-ga

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.2.3 (latest) — 2020-03-05
- 1.2.2 — 2019-10-01
- 1.2.1 — 2019-07-22
- 1.2.0 — 2019-02-22
- 1.1.0 — 2019-01-22
- 1.0.0 — 2017-12-09

## README

# react-router-ga

[![Downloads](https://img.shields.io/npm/dm/react-router-ga)](https://npm.im/react-router-ga)
[![Version](https://img.shields.io/npm/v/react-router-ga)](https://npm.im/react-router-ga)
[![License](https://img.shields.io/npm/l/react-router-ga)](https://opensource.org/licenses/MIT)

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](https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/BrowserRouter.md#basename-string) 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

```jsx
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](https://github.com/facebook/create-react-app/) and is making use of both [react-router](https://github.com/ReactTraining/react-router) and [react-router-ga](https://npm.im/react-router-ga).

Probably the code sample you are looking for is in the [`example/src/index.js` file](https://github.com/fknussel/react-router-ga/blob/master/example/src/index.js#L12-L22).

## Dependencies

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

---
_Source: https://npm.io/package/react-router-ga · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
