Skip to content

Commit eacce00

Browse files
authored
Merge pull request #440 from Neogasogaeseo/chore/#439
2 parents d383aa8 + 1e9149c commit eacce00

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

src/App.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { useEffect } from 'react';
2-
import { BrowserRouter } from 'react-router-dom';
32
import { QueryClient, QueryClientProvider } from 'react-query';
3+
import { BrowserRouter } from 'react-router-dom';
44

5-
import GlobalStyle from '@styles/global';
6-
import Router from '@routes/Router';
7-
import { useLoginUser } from '@hooks/useLoginUser';
85
import ToastList from '@components/common/Toast/List';
6+
import { GaAction, GaCategory, useGoogleAnalytics } from '@hooks/useGoogleAnalytics';
7+
import { useLoginUser } from '@hooks/useLoginUser';
8+
import Router from '@routes/Router';
9+
import GlobalStyle from '@styles/global';
10+
import ReactGA from 'react-ga';
911

1012
function App() {
11-
const { initLoginUser } = useLoginUser();
13+
const { initLoginUser, userID, isAuthenticated } = useLoginUser();
14+
const { isGoogleAnalyticsLoaded, makeGaEvent } = useGoogleAnalytics();
1215

1316
const queryClient = new QueryClient({
1417
defaultOptions: {
@@ -22,6 +25,19 @@ function App() {
2225
initLoginUser();
2326
}, []);
2427

28+
useEffect(() => {
29+
if (isGoogleAnalyticsLoaded) {
30+
makeGaEvent({
31+
category: GaCategory.INIT,
32+
action: GaAction.USER_AGENT,
33+
label: navigator.userAgent,
34+
});
35+
if (isAuthenticated) {
36+
ReactGA.set({ userID });
37+
}
38+
}
39+
}, [isGoogleAnalyticsLoaded, isAuthenticated]);
40+
2541
return (
2642
<>
2743
<GlobalStyle />

src/application/hooks/useGoogleAnalytics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { useEffect, useState } from 'react';
22
import ReactGA from 'react-ga';
33

44
export const enum GaCategory {
5+
INIT = 'init',
56
LANDING = 'landing',
67
TSS = 'tss',
78
NSS = 'nss',
89
}
910

1011
export const enum GaAction {
12+
USER_AGENT = 'user_agent',
1113
CLICK = 'click',
1214
}
1315

src/presentation/pages/Landing/index.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
import {
2+
imgGlass,
3+
imgLanding,
4+
imgLink,
5+
imgMainPage,
6+
imgMypage,
7+
imgTeamsoseo,
8+
} from '@assets/images';
9+
import TeamLandingLottie from '@assets/lottie/TeamLottie';
10+
import CommonHeader from '@components/common/Header';
11+
import { GaAction, GaCategory, useGoogleAnalytics } from '@hooks/useGoogleAnalytics';
112
import { useLoginUser } from '@hooks/useLoginUser';
2-
import { useNavigate } from 'react-router-dom';
313
import { useEffect } from 'react';
4-
import CommonHeader from '@components/common/Header';
14+
import { useNavigate } from 'react-router-dom';
515
import {
616
StFooter,
717
StLandingWrapper,
@@ -16,16 +26,6 @@ import {
1626
StServiceButton,
1727
StShadow,
1828
} from './style';
19-
import {
20-
imgGlass,
21-
imgLanding,
22-
imgLink,
23-
imgMainPage,
24-
imgMypage,
25-
imgTeamsoseo,
26-
} from '@assets/images';
27-
import TeamLandingLottie from '@assets/lottie/TeamLottie';
28-
import { GaAction, GaCategory, useGoogleAnalytics } from '@hooks/useGoogleAnalytics';
2929

3030
function Landing() {
3131
const { isAuthenticated } = useLoginUser();
@@ -49,7 +49,17 @@ function Landing() {
4949
</div>
5050
<img src={imgMainPage} />
5151
<StShadow top={161} />
52-
<StServiceButton theme="coral" onClick={() => navigate(`/login`)}>
52+
<StServiceButton
53+
theme="coral"
54+
onClick={() => {
55+
makeGaEvent({
56+
category: GaCategory.LANDING,
57+
action: GaAction.CLICK,
58+
label: 'login_top',
59+
});
60+
navigate(`/login`);
61+
}}
62+
>
5363
너가소개서 받으러 가기
5464
</StServiceButton>
5565
</StMain>

src/presentation/routes/Router.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import ScrollToTop from '@components/common/ScrollToTop';
2+
import InAppBrowserEscape from '@components/InAppBrowserEscape';
23
import { useGoogleAnalytics } from '@hooks/useGoogleAnalytics';
34
import { Suspense, useEffect } from 'react';
5+
import ReactGA from 'react-ga';
46
import { Route, Routes, useLocation } from 'react-router-dom';
7+
import FormRouter from './FormRouter';
58
import NeogaRouter from './NeogaRouter';
9+
import PreferencesRouter from './PreferencesRouter';
610
import TeamRouter from './TeamRouter';
711
import UserRouter from './UserRouter';
8-
import ReactGA from 'react-ga';
9-
import FormRouter from './FormRouter';
10-
import { useLoginUser } from '@hooks/useLoginUser';
11-
import PreferencesRouter from './PreferencesRouter';
12-
import InAppBrowserEscape from '@components/InAppBrowserEscape';
1312

1413
const Router = () => {
1514
const location = useLocation();
1615
const { isGoogleAnalyticsLoaded } = useGoogleAnalytics();
17-
const { isAuthenticated, userID } = useLoginUser();
1816

1917
useEffect(() => {
20-
if (isGoogleAnalyticsLoaded) ReactGA.pageview(location.pathname + location.search);
21-
if (isGoogleAnalyticsLoaded && isAuthenticated) {
22-
ReactGA.set({ userID });
18+
if (isGoogleAnalyticsLoaded) {
19+
ReactGA.pageview(location.pathname + location.search);
2320
}
24-
}, [isGoogleAnalyticsLoaded, location, isAuthenticated]);
21+
}, [isGoogleAnalyticsLoaded, location]);
22+
2523
return (
2624
<>
2725
<ScrollToTop />

0 commit comments

Comments
 (0)