Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 11b967d

Browse files
committed
Stop ignoring generated js
1 parent 991406d commit 11b967d

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/node_modules/
22
/Gruntfile.js
33
/test/tests.js
4-
/lib/

lib/index.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var React, ga, script, scriptIsAdded, _name,
2+
__slice = [].slice;
3+
4+
React = require('react');
5+
6+
script = React.DOM.script;
7+
8+
if (typeof window !== "undefined" && window !== null) {
9+
if (window.GoogleAnalyticsObject == null) {
10+
window.GoogleAnalyticsObject = 'ga';
11+
}
12+
}
13+
14+
if (typeof window !== "undefined" && window !== null) {
15+
if (window.ga == null) {
16+
window.ga = ga;
17+
}
18+
}
19+
20+
ga = function() {
21+
var args;
22+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
23+
return typeof window !== "undefined" && window !== null ? window[window.GoogleAnalyticsObject].apply(window, args) : void 0;
24+
};
25+
26+
if (typeof window !== "undefined" && window !== null) {
27+
if (window[_name = window.GoogleAnalyticsObject] == null) {
28+
window[_name] = function() {
29+
var api, args;
30+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
31+
api = window[window.GoogleAnalyticsObject];
32+
(api.q || (api.q = [])).push(args);
33+
};
34+
}
35+
}
36+
37+
scriptIsAdded = false;
38+
39+
ga.Initializer = React.createClass({
40+
displayName: 'GAInitializer',
41+
componentDidMount: function() {
42+
window[window.GoogleAnalyticsObject].l = new Date().getTime();
43+
if (!scriptIsAdded) {
44+
return this.addScript(this.props.protocol || 'http');
45+
}
46+
},
47+
addScript: function(protocol) {
48+
var el, s;
49+
scriptIsAdded = true;
50+
el = document.createElement('script');
51+
el.type = 'text/javascript';
52+
el.async = true;
53+
el.src = protocol + '://www.google-analytics.com/analytics.js';
54+
s = document.getElementsByTagName('script')[0];
55+
return s.parentNode.insertBefore(el, s);
56+
},
57+
render: function() {
58+
return script(null);
59+
}
60+
});
61+
62+
module.exports = ga;

0 commit comments

Comments
 (0)