Skip to content

Commit 7d704af

Browse files
author
Shabab Karim
committed
Add GA with test friendly method call
1 parent 3eabed3 commit 7d704af

3 files changed

Lines changed: 23 additions & 12 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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React, { Component } from 'react';
22
import axios from 'axios';
33
import { BrowserRouter, Route } from 'react-router-dom';
44
import { BeatLoader } from 'react-spinners';
5-
5+
import ReactGA from 'react-ga'
66
import './App.css';
77

88
import Home from './components/Home';
99
import Content from './components/Content';
10+
import AppContainer from './components/AppContainer';
1011

1112
class App extends Component {
1213
state = {
@@ -16,6 +17,13 @@ class App extends Component {
1617
loading: true
1718
}
1819

20+
constructor(props) {
21+
super(props)
22+
23+
ReactGA.initialize('UA-129387050-1', { testMode: props.isTestMode })
24+
ReactGA.pageview(window.location.href)
25+
}
26+
1927
getData() {
2028
const data = axios('https://raw.githubusercontent.com/devsonket/devsonket.github.io/develop/data/index.json');
2129
return data;
@@ -53,7 +61,7 @@ class App extends Component {
5361
render() {
5462
const { searchAItem } = this;
5563
const { tops, searchResult, data, loading } = this.state;
56-
64+
5765
if(loading) {
5866
return <div className="loader">
5967
<BeatLoader color={'#333'} />
@@ -62,14 +70,16 @@ class App extends Component {
6270

6371
return (
6472
<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>
73+
<AppContainer>
74+
<div className="App">
75+
<Route exact path="/" render={props => (
76+
<Home searchAItem={searchAItem} tops={tops} searchResult={searchResult} data={data} />
77+
)}/>
78+
<Route exact path="/:id" render={props => (
79+
<Content {...props} data={data} />
80+
)}/>
81+
</div>
82+
</AppContainer>
7383
</BrowserRouter>
7484
);
7585
}

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)