@@ -6,7 +6,7 @@ Object.defineProperty(exports, '__esModule', {
6
6
7
7
var _createClass = ( function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( 'value' in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ) ( ) ;
8
8
9
- var _get = function get ( _x3 , _x4 , _x5 ) { var _again = true ; _function: while ( _again ) { var object = _x3 , property = _x4 , receiver = _x5 ; _again = false ; if ( object === null ) object = Function . prototype ; var desc = Object . getOwnPropertyDescriptor ( object , property ) ; if ( desc === undefined ) { var parent = Object . getPrototypeOf ( object ) ; if ( parent === null ) { return undefined ; } else { _x3 = parent ; _x4 = property ; _x5 = receiver ; _again = true ; desc = parent = undefined ; continue _function; } } else if ( 'value' in desc ) { return desc . value ; } else { var getter = desc . get ; if ( getter === undefined ) { return undefined ; } return getter . call ( receiver ) ; } } } ;
9
+ var _get = function get ( _x4 , _x5 , _x6 ) { var _again = true ; _function: while ( _again ) { var object = _x4 , property = _x5 , receiver = _x6 ; _again = false ; if ( object === null ) object = Function . prototype ; var desc = Object . getOwnPropertyDescriptor ( object , property ) ; if ( desc === undefined ) { var parent = Object . getPrototypeOf ( object ) ; if ( parent === null ) { return undefined ; } else { _x4 = parent ; _x5 = property ; _x6 = receiver ; _again = true ; desc = parent = undefined ; continue _function; } } else if ( 'value' in desc ) { return desc . value ; } else { var getter = desc . get ; if ( getter === undefined ) { return undefined ; } return getter . call ( receiver ) ; } } } ;
10
10
11
11
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { 'default' : obj } ; }
12
12
@@ -18,13 +18,15 @@ var _react = require('react');
18
18
19
19
var _react2 = _interopRequireDefault ( _react ) ;
20
20
21
+ var _lodashObjectKeys = require ( 'lodash/object/keys' ) ;
22
+
23
+ var _lodashObjectKeys2 = _interopRequireDefault ( _lodashObjectKeys ) ;
24
+
21
25
function initGoogleAnalytics ( id ) {
22
- if ( window . ga ) {
23
- return ;
24
- }
26
+ var set = arguments . length <= 1 || arguments [ 1 ] === undefined ? { } : arguments [ 1 ] ;
25
27
26
- if ( ! id ) {
27
- throw new Error ( 'Google analytics ID is undefined' ) ;
28
+ if ( window . ga || ! id ) {
29
+ return ;
28
30
}
29
31
30
32
window . ga = window . ga || function ( ) {
@@ -42,6 +44,12 @@ function initGoogleAnalytics(id) {
42
44
} ) ( ) ;
43
45
44
46
window . ga ( 'create' , id , 'auto' ) ;
47
+
48
+ ( 0 , _lodashObjectKeys2 [ 'default' ] ) ( set ) . forEach ( function ( key ) {
49
+ var value = set [ key ] ;
50
+
51
+ window . ga ( 'set' , key , value ) ;
52
+ } ) ;
45
53
}
46
54
47
55
var GoogleAnalytics = ( function ( _Component ) {
@@ -58,7 +66,7 @@ var GoogleAnalytics = (function (_Component) {
58
66
value : function componentDidMount ( ) {
59
67
var _this = this ;
60
68
61
- initGoogleAnalytics ( this . props . id ) ;
69
+ initGoogleAnalytics ( this . props . id , this . props . set ) ;
62
70
63
71
this . historyListener = this . context . history . listen ( function ( err , renderProps ) {
64
72
if ( err || ! renderProps ) {
@@ -96,7 +104,7 @@ var GoogleAnalytics = (function (_Component) {
96
104
this . latestUrl = path ;
97
105
98
106
// wait for correct title
99
- setTimeout ( function wait ( ) {
107
+ setTimeout ( function ( ) {
100
108
GoogleAnalytics . sendPageview ( path , document . title ) ;
101
109
} , 0 ) ;
102
110
}
@@ -134,13 +142,14 @@ var GoogleAnalytics = (function (_Component) {
134
142
} , {
135
143
key : 'propTypes' ,
136
144
value : {
137
- id : _react2 [ 'default' ] . PropTypes . string . isRequired
145
+ id : _react . PropTypes . string ,
146
+ set : _react . PropTypes . object
138
147
} ,
139
148
enumerable : true
140
149
} , {
141
150
key : 'contextTypes' ,
142
151
value : {
143
- history : _react2 [ 'default' ] . PropTypes . object . isRequired
152
+ history : _react . PropTypes . object . isRequired
144
153
} ,
145
154
enumerable : true
146
155
} ] ) ;
0 commit comments