Skip to content

fabianzintgraf/piwik-react-router

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Piwik React Router

npm package dependency status

Piwik analytics component for react-router

Installation

npm install piwik-react-router --save

Features

  • asynchronous loading of Piwik
  • javascript error tracking

Usage

Simply create your instance with the same url and siteId as described in the piwik documentation and connect it to your history object.

Starting with v2.0 react-router won't provide a default history. Why?.

var PiwikReactRouter = require('piwik-react-router');
	
var piwik = PiwikReactRouter({
	url			: 'your-piwik-installation.com',
	siteId		: 1
});
	
<Router history={piwik.connectToHistory(history)}>
	<Route path="/" component={MyComponent} />
</Router>

If you're using react-router prior to v1.0 please head over to the react-router0.13.x branch.

Options

enableLinkTracking: true

Link tracking to track outgoing and download links is enabled by default.

updateDocumentTitle: true

Updates the document title before adding a new page view as the title may changed during the route rendering. Make sure you call piwik.track after React has rendered the <Handler /> to make this work correctly.
If you don't know how to update the title, check out the great react-document-title module.

trackErrors: false

By enabling this option occurring javascript errors will be tracked as a JavaScript Error piwik event.

see http://davidwalsh.name/track-errors-google-analytics for further details

API

track (Location location)

Adds a page view from a history Location if the path changed.

path = location.pathname + location.search

push (args)

Pushes the specified args to the Piwik tracker the same way as you're using the _paq.push(args); directly. You can use this method as the low-level api to call methods from the Piwik API, track events or call custom functions.

trackError (error, [eventName])

Tracks the given error as a new Piwik Event for the given event name. If you don't specify any name here it will fallback to JavaScript Error.

connectToHistory(history)

Adds a listener to the passed in history and triggers track(location) whenever the history changes.

disconnectFromHistory()

Disconnects Piwik from a previous connected history.

A note on serverside rendering

Piwik tracking is disabled for serverside rendering and all API methods are replaced with noop-functions so you don't have to worry about it.

About

Piwik analytics component for react-router

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%