File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 1
1
import GoogleAnalytics from 'react-ga' ;
2
2
3
- GoogleAnalytics . initialize ( process . env . GA_ID || window . GA_ID , {
4
- debug : ( process . env . NODE_ENV !== 'production' ) ,
5
- titleCase : true ,
6
- sampleRate : ( process . env . NODE_ENV === 'production' ) ? 100 : 0 ,
7
- forceSSL : true
8
- } ) ;
3
+ import log from './log' ;
4
+
5
+ const GA_ID = ( process . env . GA_ID || window . GA_ID ) ;
6
+ if ( GA_ID ) {
7
+ GoogleAnalytics . initialize ( GA_ID , {
8
+ debug : ( process . env . NODE_ENV !== 'production' ) ,
9
+ titleCase : true ,
10
+ sampleRate : ( process . env . NODE_ENV === 'production' ) ? 100 : 0 ,
11
+ forceSSL : true
12
+ } ) ;
13
+ } else {
14
+ log . info ( 'Disabling GA because GA_ID is not set.' ) ;
15
+ window . ga = ( ) => {
16
+ // The `react-ga` module calls this function to implement all Google Analytics calls. Providing an empty
17
+ // function effectively disables `react-ga`. This is similar to the `testModeAPI` feature of `react-ga` except
18
+ // that `testModeAPI` logs the arguments of every call into an array. That's nice for testing purposes but
19
+ // would look like a memory leak in a live program.
20
+ } ;
21
+ }
9
22
10
23
export default GoogleAnalytics ;
You can’t perform that action at this time.
0 commit comments