Skip to content

Commit

Permalink
구글 애널리틱스 적용되지 않는 오류 수정 (ga -> ga4로 변경) (#667)
Browse files Browse the repository at this point in the history
chore: react-ga4 패키지 추가
  • Loading branch information
gyeongza authored Oct 12, 2023
1 parent 5b54935 commit bc79576
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
19 changes: 9 additions & 10 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"history": "^5.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-ga": "^3.3.1",
"react-ga4": "^2.1.0",
"react-router-dom": "^6.14.2",
"styled-components": "^6.0.4"
},
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Suspense } from 'react';
import React, { Suspense, useEffect } from 'react';
import { styled } from 'styled-components';
import { Outlet } from 'react-router-dom';
import ToastProvider from './contexts/ToastContext';
Expand All @@ -8,22 +8,24 @@ import LoadingPage from './pages/LoadingPage';
import ModalProvider from './contexts/ModalContext';
import { QueryClientProvider, QueryErrorResetBoundary } from '@tanstack/react-query';
import { queryClient } from './hooks/query/queryClient';
import ReactGA from 'react-ga';
import { createBrowserHistory } from 'history';
import ErrorBoundary from './components/ErrorBoundary/ErrorBoundary';
import ReactGA from 'react-ga4';

const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID;
if (gaTrackingId) {
ReactGA.initialize(gaTrackingId);
}
const App = () => {
useEffect(() => {
const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID;
if (gaTrackingId) {
ReactGA.initialize(gaTrackingId);
}

const history = createBrowserHistory();
history.listen((response: { location: { pathname: string } }) => {
ReactGA.set({ page: response.location.pathname });
ReactGA.pageview(response.location.pathname);
});
const history = createBrowserHistory();
history.listen((response) => {
ReactGA.set({ page: response.location.pathname });
ReactGA.send(response.location.pathname);
});
}, []);

const App = () => {
ChannelService.loadScript();

if (CHANNEL_SERVICE_KEY) {
Expand Down

0 comments on commit bc79576

Please sign in to comment.