Your Google analytics snippet is using Analytics.js which is
a new way to measure how users interact with your website. It is similar to the previous tracking code,
ga.js
, but offers more flexibility for developers to customize their implementations.
So the API has been changed since the ga.js
which was used by the sammy-google-analytics plugin.
When you are using the Analytics.j
you need to use the new ga
function instead of the old pageTracker
object.
Luckily the plugin is very simple and there is only two places where you need to change it use the new API:
(function ($) {
Sammy = Sammy || {};
// A simple plugin that pings Google Analytics tracker
// every time a route is triggered
//
// === Arguments
//
// +trackerAccessor+:: an accessor for the Google Analytics ga function.
// Defaults to the default function defined by the analytics.js snippet,
// or pass your own tracker accessor function if you
// have a custom install
Sammy.GoogleAnalytics = function (app, trackerAccessor) {
var _trackerAccessor =
trackerAccessor || function () { return window.ga; },
shouldTrack = true;
this.helpers({
noTrack: function () {
disableTracking();
}
});
this.bind('event-context-after', function () {
if (typeof _trackerAccessor != 'undefined' && _trackerAccessor()
&& shouldTrack) {
console.log('tracking', this.path);
_trackerAccessor()('send', 'pageview', this.path);
}
enableTracking();
});
function disableTracking() {
shouldTrack = false;
}
function enableTracking() {
shouldTrack = true;
}
};
})(jQuery);
The rest of the plugin should work the same as described in its documentation:.