Skip to content

Commit 9bfaf31

Browse files
authored
Merge pull request #70 from shabab477/feature/add-google-analytics
Add GA with test friendly method call
2 parents 3eabed3 + d9f5897 commit 9bfaf31

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ npm-debug.log*
2020
yarn-debug.log*
2121
yarn-error.log*
2222

23-
.idea/*
23+
.idea/*
24+
package-lock.json

src/App.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { Component } from 'react';
22
import axios from 'axios';
3+
import ReactGA from 'react-ga';
34
import { BrowserRouter, Route } from 'react-router-dom';
45
import { BeatLoader } from 'react-spinners';
56

67
import './App.css';
78

89
import Home from './components/Home';
910
import Content from './components/Content';
11+
import AppContainer from './components/AppContainer';
1012

1113
class App extends Component {
1214
state = {
@@ -16,6 +18,13 @@ class App extends Component {
1618
loading: true
1719
}
1820

21+
constructor(props) {
22+
super(props)
23+
24+
ReactGA.initialize('UA-129387050-1', { testMode: props.isTestMode })
25+
ReactGA.pageview(window.location.href)
26+
}
27+
1928
getData() {
2029
const data = axios('https://raw.githubusercontent.com/devsonket/devsonket.github.io/develop/data/index.json');
2130
return data;
@@ -53,7 +62,7 @@ class App extends Component {
5362
render() {
5463
const { searchAItem } = this;
5564
const { tops, searchResult, data, loading } = this.state;
56-
65+
5766
if(loading) {
5867
return <div className="loader">
5968
<BeatLoader color={'#333'} />
@@ -62,14 +71,16 @@ class App extends Component {
6271

6372
return (
6473
<BrowserRouter>
65-
<div className="App">
66-
<Route exact path="/" render={props => (
67-
<Home searchAItem={searchAItem} tops={tops} searchResult={searchResult} data={data} />
68-
)}/>
69-
<Route exact path="/:id" render={props => (
70-
<Content {...props} data={data} />
71-
)}/>
72-
</div>
74+
<AppContainer>
75+
<div className="App">
76+
<Route exact path="/" render={props => (
77+
<Home searchAItem={searchAItem} tops={tops} searchResult={searchResult} data={data} />
78+
)}/>
79+
<Route exact path="/:id" render={props => (
80+
<Content {...props} data={data} />
81+
)}/>
82+
</div>
83+
</AppContainer>
7384
</BrowserRouter>
7485
);
7586
}

src/App.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import App from './App';
44

55
it('renders without crashing', () => {
66
const div = document.createElement('div');
7-
ReactDOM.render(<App />, div);
7+
ReactDOM.render(<App isTestMode={true} />, div);
88
ReactDOM.unmountComponentAtNode(div);
99
});

0 commit comments

Comments
 (0)