Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] Refactor/#505 react ga4 적용 #506

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/fe-merge-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
- name: Build project
run: npm run build
working-directory: frontend
env:
REACT_APP_GOOGLE_ANALYTICS: ${{ secrets.REACT_APP_GOOGLE_ANALYTICS }}

- name: upload to artifact
uses: actions/upload-artifact@v3
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/fe-merge-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

pull_request:
branches: [ main ]
branches: [main]
types: [closed]
paths: frontend/**

Expand All @@ -23,8 +23,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: "frontend"
cache: 'npm'
cache-dependency-path: 'frontend'

- name: Install npm
run: npm install
Expand All @@ -33,6 +33,8 @@ jobs:
- name: Build project
run: npm run build
working-directory: frontend
env:
REACT_APP_GOOGLE_ANALYTICS: ${{ secrets.REACT_APP_GOOGLE_ANALYTICS }}

- name: upload to artifact
uses: actions/upload-artifact@v3
Expand All @@ -41,7 +43,7 @@ jobs:
path: frontend/dist

deploy:
runs-on: [ self-hosted, prod]
runs-on: [self-hosted, prod]
needs: build-and-upload

if: github.event.pull_request.merged
Expand Down
36,345 changes: 9,323 additions & 27,022 deletions frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"msw-storybook-addon": "^1.8.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.1",
"styled-components": "^6.0.3"
},
Expand Down
15 changes: 0 additions & 15 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
src="https://apis.openapi.sk.com/tmap/vectorjs?version=1&&appKey=P2MX6F1aaf428AbAyahIl9L8GsIlES04aXS9hgxo"
></script>
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>

<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-RRSTX6Y61Y"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'G-RRSTX6Y61Y');
</script>
<title>괜찮을지도</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* tslint:disable */

/**
* Mock Service Worker (1.2.3).
* Mock Service Worker (1.3.1).
* @see https://github.com/mswjs/msw
* - Please do NOT modify this file.
* - Please do NOT serve this file on production.
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RouterProvider } from 'react-router-dom';
import router from './router';
import RouteChangeTracker from './utils/RouteChangeTracker';

const App = () => {
RouteChangeTracker();

return <RouterProvider router={router} />;
};

Expand Down
25 changes: 25 additions & 0 deletions frontend/src/utils/RouteChangeTracker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import ReactGA from 'react-ga4';

const RouteChangeTracker = () => {
const location = useLocation();
const [initialized, setInitialized] = useState(false);

useEffect(() => {
if (process.env.REACT_APP_GOOGLE_ANALYTICS) {
ReactGA.initialize(process.env.REACT_APP_GOOGLE_ANALYTICS);
setInitialized(true);
}
}, []);

// location 변경 감지시 pageview 이벤트 전송
useEffect(() => {
if (initialized) {
ReactGA.set({ page: location.pathname });
ReactGA.send('pageview');
}
}, [initialized, location]);
};

export default RouteChangeTracker;
Loading