This repository has been archived by the owner on Jul 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Analytics.js
58 lines (42 loc) · 1.71 KB
/
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
Ext.ux.Analytics = Ext.extend(Ext.util.Observable, {
isInitiated: false,
constructor: function(config) {
this.acct = config.acct;
this.addEvents({
'scriptload': true,
'pagetrack': true,
'eventtrack': true
});
this.listeners = config.listeners;
this.on('scriptload', this.onScriptLoad, this);
this.loadScript();
Ext.ux.Analytics.superclass.constructor.call(config)
},
loadScript: function() {
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
this.tag = document.createElement('script');
this.tag.src = gaJsHost + 'google-analytics.com/ga.js';
this.tag.type = 'text/javascript';
this.tag.onload = this.onScriptLoad.createDelegate(this);
this.tag.onreadystatechange = this.onReadyStateChange.createDelegate(this);
document.getElementsByTagName('head')[0].appendChild(this.tag);
},
onReadyStateChange: function() {
if (('loaded' === this.tag.readyState || 'complete' === this.tag.readyState) && !this.isInitiated) {
this.fireEvent('scriptload');
}
},
onScriptLoad: function() {
this._tracker = _gat._getTracker(this.acct);
this.trackPageView();
this.isInitiated = true;
},
trackPageView: function(page){
this._tracker._trackPageview(page);
this.fireEvent('pagetrack', page);
},
trackEvent: function(category, action){
this._tracker._trackEvent(category, action);
this.fireEvent('eventtrack', category, action);
}
});