Skip to content

Commit

Permalink
Feature/#81 (#82)
Browse files Browse the repository at this point in the history
* feat: add firebase and remove @amplitude/analytics-browser dependency

* refactor: remove existing GA

* refactor: 필요없는 조건문 삭제
  • Loading branch information
박상현 authored Apr 19, 2024
1 parent 518dc9b commit 98f6027
Show file tree
Hide file tree
Showing 10 changed files with 718 additions and 155 deletions.
776 changes: 692 additions & 84 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@amplitude/analytics-browser": "^1.4.0",
"@b1nd/b1nd-design-core": "^1.0.4",
"@b1nd/b1nd-react-util": "^1.0.2",
"@b1nd/b1nd-styled-components-theme": "^1.0.4",
Expand All @@ -21,6 +20,7 @@
"dayjs": "^1.11.5",
"dotenv": "^16.0.3",
"esbuild": "^0.15.5",
"firebase": "^10.11.0",
"js-cookie": "^3.0.1",
"js-sha512": "^0.8.0",
"react": "^18.2.0",
Expand Down
10 changes: 1 addition & 9 deletions src/components/common/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as S from "./style";
import logo from "@src/assets/logo/dodam_text_logo.svg";
import { AiFillInfoCircle } from "@react-icons/all-files/ai/AiFillInfoCircle";
import { HEADER_LINKS } from "@src/constants/header/header.constant";
import { pageView } from "@src/lib/ga/gtag";
import { track } from "@amplitude/analytics-browser";

const Header = () => {
const currentSelect = "홈";
Expand All @@ -20,13 +18,7 @@ const Header = () => {
isSelect={link.name === currentSelect}
key={`header/${link.name}Item`}
>
<span
onClick={() => {
pageView(link.name);
track(link.name + "접속");
window.location.href = link.link;
}}
>
<span onClick={() => (window.location.href = link.link)}>
{link.name}
</span>
</S.HeaderItem>
Expand Down
7 changes: 1 addition & 6 deletions src/components/home/MyInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React, { useEffect } from "react";
import React from "react";
import MyInfoHeader from "./MyInfoHeader";
import MyInfoWakeupSong from "./MyInfoWakeupSong";
import MyInfoTopImage from "@src/assets/images/myinfo/myInfoTop.svg";
import * as S from "./style";
import { track } from "@amplitude/analytics-browser";

const MyInfo = () => {
useEffect(() => {
track("(메인페이지)내 기상송 조회");
}, []);

return (
<S.MyInfoContainer style={{ marginLeft: "auto" }}>
<S.MyInfoTopIcon src={MyInfoTopImage} alt="myInfo myInfoTopImage" />
Expand Down
4 changes: 3 additions & 1 deletion src/components/home/Point/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import PointChartIcon from "@src/assets/icons/point/pointChart.png";
import { useRecoilState } from "recoil";
import { pointViewTypeAtom } from "@src/store/point/pointStore";
import { ErrorBoundary } from "react-error-boundary";
import { Suspense } from "react";
import { Suspense, useEffect } from "react";
import PointDashBoard from "./PointDashBoard";
import PointDashBoardFallbackLoader from "@src/components/common/FallbackLoader/PointDashBoard";
import ErrorFallback from "@src/components/common/ErrorFallback";
import { useLogGA } from "@src/hooks/ga/useLogGA";

const Point = () => {
const [isDormitoryPointView, setIsDormitoryPointView] =
useRecoilState(pointViewTypeAtom);
const { handleGALogEvent } = useLogGA();

const onChangeView = () => {
setIsDormitoryPointView((prev) =>
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/ga/useLogGA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getAnalytics, logEvent } from "firebase/analytics";
import { initializeApp } from "firebase/app";
import CONFIG from "@src/config/config.json";

export const useLogGA = () => {
const app = initializeApp(CONFIG.GOOGLE_ANALYTICS);
const analytics = getAnalytics(app);

const handleGALogEvent = (view: string) => {
logEvent(analytics, view);
};

return {
handleGALogEvent,
};
};
6 changes: 2 additions & 4 deletions src/hooks/meal/useHandleMealDate.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { track } from "@amplitude/analytics-browser";
import dayjs from "dayjs";
import { useRecoilState } from "recoil";
import { mealDateAtom } from "@src/store/meal/mealStore";
import { useLogGA } from "../ga/useLogGA";

const useHandleMealDate = () => {
const [, setDate] = useRecoilState(mealDateAtom);
const { handleGALogEvent } = useLogGA();

const handleMealDate = (e: Date) => {
setDate(dayjs(e).format("YYYY-MM-DD"));
track("(메인페이지) 급식조회");
};

const prevMealDate = () => {
setDate((prev) => dayjs(prev).subtract(1, "day").format("YYYY-MM-DD"));
track("(메인페이지) 급식조회");
};

const nextMealDate = () => {
setDate((prev) => dayjs(prev).add(1, "day").format("YYYY-MM-DD"));
track("(메인페이지) 급식조회");
};

return {
Expand Down
10 changes: 0 additions & 10 deletions src/hooks/pass/useApplyPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,6 @@ const useApplyPass = () => {
),
};

console.log(typeof validApplyPass.endAt);

if (
typeof validApplyPass.endAt === "string" ||
typeof validApplyPass.startAt === "string"
) {
showToast("시간형식을 올바르게 지정해주세요!", "INFO");
return;
}

if (validApplyPass.reason.trim() === "") {
showToast("외출사유를 작성해주세요!", "INFO");
return;
Expand Down
22 changes: 0 additions & 22 deletions src/lib/ga/gtag.ts

This file was deleted.

20 changes: 2 additions & 18 deletions src/pages/homePage.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import { useLogGA } from "@src/hooks/ga/useLogGA";
import PageTemplate from "../components/common/PageTemplate";
import Home from "../components/home";
import { init, track } from "@amplitude/analytics-browser";
import { useEffect } from "react";
import ReactGA from "react-ga4";
import { pageView } from "../lib/ga/gtag";
import useTokenCheck from "../hooks/auth/useTokenCheck";

const HomePage = () => {
useEffect(() => {
if (!window.location.href.includes("localhost")) {
if (process.env.GOOGLE_ANALYTICS_ID) {
ReactGA.initialize(process.env.GOOGLE_ANALYTICS_ID);
pageView("메인페이지");
}

if (process.env.AMPLITUDE_KEY) {
init(process.env.AMPLITUDE_KEY);
track("메인페이지 접속");
}
}
}, []);

useTokenCheck();
const { handleGALogEvent } = useLogGA();

return (
<PageTemplate>
Expand Down

0 comments on commit 98f6027

Please sign in to comment.