-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbackbone.analytics.js
107 lines (107 loc) · 3.74 KB
/
backbone.analytics.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice;
window.Backbone.Analytics = (function() {
function Analytics(options) {
if (options == null) {
options = {};
}
this.trackNavigate = __bind(this.trackNavigate, this);
this.setCustomVar = __bind(this.setCustomVar, this);
this.trackSocial = __bind(this.trackSocial, this);
this.trackEvent = __bind(this.trackEvent, this);
this.trackPageview = __bind(this.trackPageview, this);
this.setAccount = __bind(this.setAccount, this);
this.push = __bind(this.push, this);
this.queue = __bind(this.queue, this);
this.script = __bind(this.script, this);
this.protocol = __bind(this.protocol, this);
this.loadScript = __bind(this.loadScript, this);
this.initialize = __bind(this.initialize, this);
this.code = options.code;
this.debug = options.debug;
if (options.setAccount !== false) {
this.setAccount();
}
if (options.loadScript !== false) {
this.loadScript();
}
this.initialize.apply(this, arguments);
if (options.initialPageview !== false) {
this.trackPageview();
}
if (options.trackNavigate !== false) {
this.trackNavigate();
}
}
Analytics.prototype.initialize = function() {};
Analytics.prototype.loadScript = function() {
var ga, s;
ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = this.protocol() + this.script();
s = document.getElementsByTagName('script')[0];
return s.parentNode.insertBefore(ga, s);
};
Analytics.prototype.protocol = function() {
if (document.location.protocol === 'https:') {
return 'https://ssl';
} else {
return 'http://www';
}
};
Analytics.prototype.script = function() {
if (this.debug === true) {
return '.google-analytics.com/u/ga_debug.js';
} else {
return '.google-analytics.com/ga.js';
}
};
Analytics.prototype.queue = function() {
return window._gaq || (window._gaq = []);
};
Analytics.prototype.push = function(args) {
return this.queue().push(args);
};
Analytics.prototype.setAccount = function() {
if (this.code != null) {
return this.push(['_setAccount', this.code]);
} else {
throw new Error("Cannot Set Google Analytics Account: No Tracking Code Provided");
}
};
Analytics.prototype.trackPageview = function(fragment) {
var command;
command = ['_trackPageview'];
if (fragment != null) {
command.push(fragment);
}
return this.push(command);
};
Analytics.prototype.trackEvent = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.push(['_trackEvent'].concat(args));
};
Analytics.prototype.trackSocial = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.push(['_trackSocial'].concat(args));
};
Analytics.prototype.setCustomVar = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.push(['_setCustomVar'].concat(args));
};
Analytics.prototype.trackNavigate = function() {
var navigate, trackPageview;
trackPageview = this.trackPageview;
navigate = window.Backbone.History.prototype.navigate;
return window.Backbone.History.prototype.navigate = function(fragment, options) {
trackPageview(fragment);
return navigate.apply(this, arguments);
};
};
return Analytics;
})();
}).call(this);