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 pathreact-google-analytics.js
67 lines (57 loc) · 2.34 KB
/
react-google-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
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.ReactGoogleAnalytics=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
var React, ga, script, scriptIsAdded, _name,
__slice = [].slice;
React = (window.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();
}
},
addScript: function() {
var el, s;
scriptIsAdded = true;
el = document.createElement('script');
el.type = 'text/javascript';
el.async = true;
el.src = '//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;
},{}]},{},[1])
(1)
});