New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ga-react-router

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ga-react-router

Google analytics component for react-router

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Google analytics for any router

This doesn't have any depency on react-router. You can use it with any router you like. See the example for how to use it with react-router

How to use

  1. npm install ga-react-router
  2. In your webpack.config.js add new webpack.DefinePlugin({GA_TRACKING_CODE: JSON.stringify('XXXXXXXX')})
  3. Use analytics in your Router.run code.

Example

import ga from 'ga-react-router'
import createBrowserHistory from 'history/lib/createBrowserHistory'
const history = createBrowserHistory()

// Listen for changes to the current location. The
// listener is called once immediately.
const unlisten = history.listen(location => {
  ga('send', location);
});

React.render(<Router history={history}>{routes}</Router>, el)

// When you're finished, stop the listener.
unlisten()

Advanced setup

You can pass more information to ga.create() by adding a GA_CONFIG object to webpack.DefinePlugin like so:

new webpack.DefinePlugin({
  GA_TRACKING_CODE: JSON.stringify('XXXXXXXX'),
  GA_CONFIG: {
    'name': 'myTracker'
  }
})

You can read further on the subject here.

FAQs

Package last updated on 15 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc