How to set up Google Analytics for React-Router?

Keep a reference to your history object. i.e. import { createBrowserHistory } from ‘history’; var history = createBrowserHistory(); ReactDOM.render(( <Router history={history}> […] Then add a listener to record each pageview. (This assumes you’ve already set up the window.ga object in the usual manner.) history.listen((location) => { window.ga(‘set’, ‘page’, location.pathname + location.search); window.ga(‘send’, ‘pageview’); });

Tracking Google Analytics Page Views with AngularJS

If you’re using ng-view in your Angular app you can listen for the $viewContentLoaded event and push a tracking event to Google Analytics. Assuming you’ve set up your tracking code in your main index.html file with a name of var _gaq and MyCtrl is what you’ve defined in the ng-controller directive. function MyCtrl($scope, $location, $window) … Read more

Can you test google analytics on a localhost address?

This question remains valid today, however the technology has changed. The old Urchin tracker is deprecated and obsolete. The new asynchronous Google Analytics tracking code uses slightly different code to achieve the same results. Google Analytics Classic – Asynchronous Syntax – ga.js The current syntax for setting the tracking domain to none on google analytics … Read more