This repository was archived by the owner on Mar 14, 2024. It is now read-only.
forked from hzdg/react-google-analytics
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
62 lines (53 loc) · 1.63 KB
/
index.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
var React, ga, script, scriptIsAdded, _name,
__slice = [].slice;
React = require('react');
script = React.DOM.script;
if (typeof window !== "undefined" && window !== null) {
if (window.GoogleAnalyticsObject == null) {
window.GoogleAnalyticsObject = 'ga';
}
}
if (typeof window !== "undefined" && window !== null) {
if (window.ga == null) {
window.ga = ga;
}
}
ga = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return typeof window !== "undefined" && window !== null ? window[window.GoogleAnalyticsObject].apply(window, args) : void 0;
};
if (typeof window !== "undefined" && window !== null) {
if (window[_name = window.GoogleAnalyticsObject] == null) {
window[_name] = function() {
var api, args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
api = window[window.GoogleAnalyticsObject];
(api.q || (api.q = [])).push(args);
};
}
}
scriptIsAdded = false;
ga.Initializer = React.createClass({
displayName: 'GAInitializer',
componentDidMount: function() {
window[window.GoogleAnalyticsObject].l = new Date().getTime();
if (!scriptIsAdded) {
return this.addScript(this.props.protocol || 'http');
}
},
addScript: function(protocol) {
var el, s;
scriptIsAdded = true;
el = document.createElement('script');
el.type = 'text/javascript';
el.async = true;
el.src = protocol + '://www.google-analytics.com/analytics.js';
s = document.getElementsByTagName('script')[0];
return s.parentNode.insertBefore(el, s);
},
render: function() {
return script(null);
}
});
module.exports = ga;