Skip to content

Commit

Permalink
feat: react-ga4 연동완료 #430
Browse files Browse the repository at this point in the history
  • Loading branch information
novice0840 committed Dec 23, 2024
1 parent 5a6b0e4 commit 1f8fbc9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
38 changes: 36 additions & 2 deletions frontend/package-lock.json

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

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"copy-webpack-plugin": "^12.0.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-ga4": "^2.1.0",
"react-qr-code": "^2.0.15",
"react-router-dom": "^6.24.1",
"recoil": "^0.7.7"
Expand Down Expand Up @@ -58,6 +59,7 @@
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@types/node": "^22.10.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.16.0",
Expand Down Expand Up @@ -112,4 +114,4 @@
"public"
]
}
}
}
6 changes: 4 additions & 2 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'G-3BFVVPQT0Z');
if (process.env.NODE_ENV == 'production') {
gtag('js', new Date());
gtag('config', 'G-3BFVVPQT0Z');
}
</script>

<body>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/router/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { useEffect } from 'react';
import ReactGA from 'react-ga4';
import { Outlet } from 'react-router-dom';

import AsyncErrorBoundary from '@/components/common/ErrorBoundary/AsyncErrorBoundary';
import RootErrorBoundary from '@/components/common/ErrorBoundary/RootErrorBoundary';
import ModalProvider from '@/providers/ModalProvider/ModalProvider';

const MainLayout = () => {
useEffect(() => {
ReactGA.initialize('G-3BFVVPQT0Z');
ReactGA.send({ hitType: 'pageview', page: '/my-path', title: 'Custom Title' });
});

return (
<RootErrorBoundary>
<AsyncErrorBoundary>
Expand Down

0 comments on commit 1f8fbc9

Please sign in to comment.