Skip to content

Commit b7b0517

Browse files
committed
fix: don't initialize|track GA events in development
1 parent 40f526d commit b7b0517

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/config/analytics.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const ReactGA = require('react-ga')
2-
ReactGA.initialize('UA-86342987-2')
32

43
export const logPageView = () => {
54
ReactGA.set({ page: window.location.pathname })

src/containers/Main/MainContainer.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,31 @@ import { logPageView } from 'config/analytics'
88
import s from './Main.scss'
99

1010
class MainContainer extends Component {
11-
constructor() {
12-
super()
13-
this.state = {
14-
screenWidth: 0,
15-
menuHeight: 0,
16-
isMenuOpen: false
17-
}
18-
this.triggerMenu = this.triggerMenu.bind(this)
19-
this.hideMenu = this.hideMenu.bind(this)
20-
this.getScreenWidth = this.getScreenWidth.bind(this)
11+
state = {
12+
screenWidth: 0,
13+
menuHeight: 0,
14+
isMenuOpen: false
2115
}
2216

2317
componentDidMount() {
2418
/* eslint-disable-next-line */
25-
console.log('asappppppppppp')
19+
console.log('asap', process.env.NODE_ENV, Date.now())
2620
this.loadFonts()
2721
this.getScreenWidth()
2822
window.addEventListener('resize', this.getScreenWidth)
2923
}
3024

3125
componentDidUpdate() {
32-
logPageView()
26+
if (process.env.NODE_ENV === 'production') {
27+
logPageView()
28+
}
3329
}
3430

3531
componentWillUnmount() {
3632
window.removeEventListener('resize', this.getScreenWidth)
3733
}
3834

39-
loadFonts() {
35+
loadFonts = () => {
4036
WebFont.load({
4137
google: { families: ['Comfortaa:300,400,700'] },
4238
active() {
@@ -46,7 +42,7 @@ class MainContainer extends Component {
4642
})
4743
}
4844

49-
getScreenWidth() {
45+
getScreenWidth = () => {
5046
this.setState({ screenWidth: window.innerWidth }, () => {
5147
const header = document.querySelector('header')
5248
const navHeight = header.querySelector('nav').scrollHeight
@@ -63,7 +59,8 @@ class MainContainer extends Component {
6359
}
6460
})
6561
}
66-
triggerMenu() {
62+
63+
triggerMenu = () => {
6764
const header = document.querySelector('header')
6865
const navHeight = header.querySelector('nav').scrollHeight
6966
if (this.state.isMenuOpen) {
@@ -76,7 +73,8 @@ class MainContainer extends Component {
7673
menuHeight: !this.state.isMenuOpen ? navHeight : 0
7774
})
7875
}
79-
hideMenu(event) {
76+
77+
hideMenu = event => {
8078
let el = event.target || event.srcElement
8179
while (el) {
8280
if (el.nodeName === 'A') {
@@ -86,11 +84,13 @@ class MainContainer extends Component {
8684
el = el.parentNode
8785
}
8886
}
87+
8988
render() {
9089
const { isMenuOpen, menuHeight } = this.state
9190
const appHeight = {
9291
height: isMenuOpen ? `calc(100% + ${menuHeight / 2}px)` : '100%'
9392
}
93+
9494
return (
9595
<div className={s.outerContainer} style={appHeight}>
9696
<Header triggerMenu={this.triggerMenu} {...this.state} />

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import { render } from 'react-dom'
33
import { BrowserRouter as Router } from 'react-router-dom'
44
import { AppContainer } from 'react-hot-loader'
5+
import ReactGA from 'react-ga'
56
import * as Sentry from '@sentry/browser'
67

78
import { MainContainer as Root } from 'containers'
@@ -12,6 +13,7 @@ if (process.env.NODE_ENV === 'production') {
1213
Sentry.init({
1314
dsn: 'https://66e8a28472ba439eabfa9cb013eaa1b4@sentry.io/1540454'
1415
})
16+
ReactGA.initialize('UA-86342987-2')
1517
}
1618

1719
const renderApp = Root => {

0 commit comments

Comments
 (0)