Skip to content

Commit 44a75d5

Browse files
committed
GA works
1 parent 1bc01bc commit 44a75d5

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
SENTRY_DSN='https://XXXX.ingest.sentry.io/00000000'
2-
GA_GCODE='G-XXXXXXXXXXX'
2+
GA_UACODE=UA-XXXXXXXXXX

src/screens/Main.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ import TaskControl from '../components/TaskControl/TaskControl';
77
import HeaderMenu from '../components/HeaderMenu/HeaderMenu';
88
import HoursScreen from './hours/HoursScreen';
99
import Dashboard from './dashboard/Dashboard';
10-
import analytics from '../services/GaService';
10+
import GaService from '../services/GaService';
1111

1212
const { Header } = Layout;
1313

1414
const Main = () => {
1515
const location = useLocation();
1616

1717
useEffect(() => {
18-
analytics?.pageview(location.pathname).event('Event', 'test').send();
18+
let path = location.pathname;
19+
if (path.includes('index.html')) {
20+
path = '/';
21+
}
22+
GaService.pageView(path);
1923
}, [location.pathname]);
2024

2125
return (
@@ -34,10 +38,10 @@ const Main = () => {
3438
<TaskControl />
3539
</Header>
3640
<Switch>
37-
<Redirect exact from="/" to="/projects" />
3841
<Route path="/hours" component={HoursScreen} />
3942
<Route path="/projects" component={ProjectsScreen} />
4043
<Route path="/dashboard" component={Dashboard} />
44+
<Redirect from="*" to="/projects" />
4145
</Switch>
4246
</Layout>
4347
);

src/services/GaService.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import ua from 'universal-analytics';
22

3-
const gaCode = process.env.GA_GCODE;
3+
const isProd = true; //process.env.NODE_ENV === 'production';
4+
5+
const gaCode = process.env.GA_UACODE;
46
let analytics: any | null = null;
57
console.log(gaCode);
68
if (gaCode) {
79
debugger;
810
analytics = ua(gaCode);
911
}
1012

11-
export default analytics;
13+
const GaService = {
14+
pageView(path: string) {
15+
if (isProd) {
16+
analytics?.pageview(path).send();
17+
}
18+
},
19+
event(category: string, action: string) {
20+
if (isProd) {
21+
analytics?.event(category, action).send();
22+
}
23+
},
24+
};
25+
26+
export default GaService;

yarn.lock

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10460,15 +10460,6 @@ universal-analytics@^0.4.23:
1046010460
request "^2.88.2"
1046110461
uuid "^3.0.0"
1046210462

10463-
universal-analytics@0.4.23:
10464-
version "0.4.23"
10465-
resolved "https://registry.yarnpkg.com/universal-analytics/-/universal-analytics-0.4.23.tgz#d915e676850c25c4156762471bdd7cf2eaaca8ac"
10466-
integrity sha512-lgMIH7XBI6OgYn1woDEmxhGdj8yDefMKg7GkWdeATAlQZFrMrNyxSkpDzY57iY0/6fdlzTbBV03OawvvzG+q7A==
10467-
dependencies:
10468-
debug "^4.1.1"
10469-
request "^2.88.2"
10470-
uuid "^3.0.0"
10471-
1047210463
universalify@^0.1.0:
1047310464
version "0.1.2"
1047410465
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"

0 commit comments

Comments
 (0)