Skip to content

Instantly share code, notes, and snippets.

@nordfjord
Created March 22, 2016 15:47
Show Gist options
  • Save nordfjord/23f05ffeb03247dcae50 to your computer and use it in GitHub Desktop.
Save nordfjord/23f05ffeb03247dcae50 to your computer and use it in GitHub Desktop.
Google Analytics integration for mithril
var m = require('mithril');
var _mroute = m.route;
var type = {}.toString;
m.route = function(arg0, arg1){
var res = m_route.apply(this, [].slice.call(arguments));
if (type.call(arguments[0]) === '[object String]' || (arguments.length === 3 && type.call(arg1) === '[object String]')) {
ga('send', 'pageview', _mroute());
}
return res;
};
m.route.strategy = _mroute.strategy;
@adenhertog
Copy link

adenhertog commented May 31, 2021

per google's recommendation (https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications#tracking_virtual_pageviews), the ga portion should be:

ga('set', 'page', _mroute());
ga('send', 'pageview');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment