This repository was archived by the owner on Dec 21, 2022. It is now read-only.
forked from kendagriff/backbone.analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackbone.analytics.js
More file actions
48 lines (37 loc) · 1.29 KB
/
Copy pathbackbone.analytics.js
File metadata and controls
48 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Created by Kendall Buchanan, (https://github.com/kendagriff)
// Modified by Paul English, (https://github.com/nrub)
// MIT licence
// Version 0.0.2
(function() {
var _loadUrl = Backbone.History.prototype.loadUrl
_navigate = Backbone.History.prototype.navigate;
Backbone.History.prototype.loadUrl = function(fragmentOverride) {
var matched = _loadUrl.apply(this, arguments);
Backbone.History.prototype.trackUrl.apply(this);
return matched;
};
Backbone.History.prototype.trackUrl = function () {
var fragment = this.fragment;
// Normalise fragment with leading slash
if (!/^\//.test(fragment)) fragment = '/' + fragment;
// Ensure we aren't double tracking an already tracked fragment
if (fragment !== this.lastTrackedFragment) {
if (window._gaq !== undefined) window._gaq.push(['_trackPageview', fragment]);
this.lastTrackedFragment = fragment;
}
};
Backbone.History.prototype.navigate = function(fragment, options) {
var result = _navigate.apply(this, arguments);
if (!options || options === true) options = {
track: true,
trigger: options
};
if (_.isUndefined(options.track)) {
options.track = true;
}
if (options.track) {
this.trackUrl();
}
return result;
};
}).call(this);