Skip to content

Commit b261908

Browse files
committed
feat: GA click event
1 parent 2b59eb3 commit b261908

File tree

5 files changed

+84
-21
lines changed

5 files changed

+84
-21
lines changed

src/components/Banner.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
22
import { Link } from "react-router-dom";
33
import { cls } from "@/utils/cls";
44
import Indicator from "@/components/Indicator";
5+
import { trackEvent } from "@/libs/analytics";
56

67
interface BannerImage {
78
sm: string;
@@ -28,12 +29,14 @@ const bannerImages: BannerImage[] = [
2829
md: "/image/home_banner3_md.png",
2930
lg: "/image/home_banner3_lg.png",
3031
description: "MBTI별 피해야 할 대화스타일 및 주제"
31-
},
32+
}
3233
];
3334

3435
const Banner = () => {
3536
const [order, setOrder] = useState<number>(0);
3637

38+
const bannerEventElements = ["배너 1", "배너 2", "배너 3"];
39+
3740
useEffect(() => {
3841
const interval = setInterval(() => {
3942
setOrder((prev) => (prev + 1) % bannerImages.length);
@@ -43,18 +46,33 @@ const Banner = () => {
4346

4447
return (
4548
<div className="relative flex h-[184px] w-full">
46-
<Link to={order === 0 ? "/mbti-test" : `/contents/${order}`} className="absolute w-full h-full">
49+
<Link
50+
to={order === 0 ? "/mbti-test" : `/contents/${order}`}
51+
className="absolute h-full w-full"
52+
onClick={() => {
53+
if (bannerEventElements[order]) {
54+
trackEvent("Click", {
55+
page: "홈",
56+
element: bannerEventElements[order]
57+
});
58+
}
59+
}}
60+
>
4761
{bannerImages.map((image, index) => (
4862
<picture
4963
key={index}
5064
className={cls(
51-
"absolute transition-opacity duration-500 w-full h-full",
65+
"absolute h-full w-full transition-opacity duration-500",
5266
order === index ? "opacity-100" : "opacity-0"
5367
)}
5468
>
5569
<source media="(min-width: 500px)" srcSet={image.lg} />
5670
<source media="(min-width: 375px)" srcSet={image.md} />
57-
<img src={image.sm} alt={image.description} className="w-full h-full object-cover" />
71+
<img
72+
src={image.sm}
73+
alt={image.description}
74+
className="h-full w-full object-cover"
75+
/>
5876
</picture>
5977
))}
6078
</Link>

src/components/button/ChatStartButton.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import { useNavigate } from "react-router-dom";
2-
3-
const ChatStartButton = ({mode} : {mode: "go-fast" | "go-virtual" | "go-chat"}) => {
2+
import { trackEvent } from "@/libs/analytics";
3+
const ChatStartButton = ({
4+
mode
5+
}: {
6+
mode: "go-fast" | "go-virtual" | "go-chat";
7+
}) => {
48
const navigate = useNavigate();
59

610
const handleNavigate = () => {
7-
switch(mode) {
8-
case "go-fast" : navigate("/select-info", {state:"fastFriend"});
9-
break;
10-
case "go-virtual" : navigate("/select-info", {state:"virtualFriend"});
11-
break;
12-
case "go-chat" : navigate("/chat");
13-
break;
14-
default : console.error("mode is invalid", mode);
15-
return;
11+
switch (mode) {
12+
case "go-fast":
13+
trackEvent("Click", {
14+
page: "홈",
15+
element: "빠른 대화 시작"
16+
});
17+
navigate("/select-info", { state: "fastFriend" });
18+
break;
19+
case "go-virtual":
20+
trackEvent("Click", {
21+
page: "홈",
22+
element: "친구 - 바로 대화하기"
23+
});
24+
navigate("/select-info", { state: "virtualFriend" });
25+
break;
26+
case "go-chat":
27+
navigate("/chat");
28+
break;
29+
default:
30+
console.error("mode is invalid", mode);
31+
return;
1632
}
17-
}
33+
};
1834
return (
1935
<button
2036
className="flex h-[56px] w-[320px] items-center justify-center rounded-lg bg-primary-normal font-bold text-white md:w-[335px] lg:w-[460px]"

src/pages/Chat.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import ChatActionBar from "@/components/ChatActionBar";
66
import pickMbtiImage from "@/utils/pickMbtiImage";
77
import instance from "@/api/axios";
88
import { useLocation } from "react-router-dom";
9-
import { cls } from "@/utils/cls";
109
import TipsMenuContainer from "@/components/tips/TipsMenuContainer";
10+
import { trackEvent } from "@/libs/analytics";
1111

1212
interface Message {
1313
role: "user" | "assistant";
@@ -27,13 +27,24 @@ const Chat = () => {
2727
const [isOpen, setIsOpen] = useState(false);
2828
const bottomRef = useRef<HTMLDivElement | null>(null);
2929

30+
const chatTitle = `${mbti}와 대화`;
31+
const assistantInfo = mbti;
32+
const assistantImgUrl = pickMbtiImage(assistantInfo);
33+
3034
useEffect(() => {
3135
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
3236
}, [messages, isOpen]);
3337

34-
const chatTitle = `${mbti}와 대화`;
35-
const assistantInfo = mbti;
36-
const assistantImgUrl = pickMbtiImage(assistantInfo);
38+
const handleToggleTips = () => {
39+
const nextAction = !isOpen;
40+
41+
trackEvent("Click", {
42+
page: "채팅방",
43+
element: nextAction ? "콘텐츠 열기" : "콘텐츠 닫기"
44+
});
45+
46+
setIsOpen(nextAction);
47+
};
3748

3849
const handleSend = async (messageToSend: string) => {
3950
if (!messageToSend.trim()) return;
@@ -127,7 +138,7 @@ const Chat = () => {
127138
</div>
128139
<ChatActionBar
129140
isOpen={isOpen}
130-
setIsOpen={setIsOpen}
141+
setIsOpen={handleToggleTips}
131142
value={input}
132143
onChange={handleChange}
133144
onKeyUp={handleKeyup}

src/pages/MyInfo.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ActionConfirmModal from "@/components/modal/ActionConfirmModal";
44
import useAuthStore from "@/store/useAuthStore";
55
import { useNavigate } from "react-router-dom";
66
import TermsAndPrivacyModal from "@/components/modal/TermsAndPrivacyModal";
7+
import { trackEvent } from "@/libs/analytics";
78

89
type ModalType = "logout" | "withdraw" | "terms" | "privacy" | null;
910

@@ -33,9 +34,17 @@ const MyInfo = () => {
3334

3435
const handleConfirm = () => {
3536
if (modalType === "logout") {
37+
trackEvent("Click", {
38+
page: "내 정보",
39+
element: "로그아웃"
40+
});
3641
logout();
3742
navigate("/login");
3843
} else if (modalType === "withdraw") {
44+
trackEvent("Click", {
45+
page: "내 정보",
46+
element: "회원탈퇴"
47+
});
3948
console.log("회원탈퇴 실행"); //TODO: 회원탈퇴 기능 구현 시 추가 필요
4049
}
4150
setModalType(null);

src/pages/SelectInfo.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Header from "@/components/header/Header";
55
import { getMBTIgroup, mapAgeToNumber } from "@/utils/helpers";
66
import instance from "@/api/axios";
77
import ToastMessage from "@/components/ToastMessage";
8+
import { trackEvent } from "@/libs/analytics";
89

910
type FastFriendResponse = {
1011
header: {
@@ -182,6 +183,10 @@ const SelectInfo = () => {
182183
const responseData = response.data.data;
183184

184185
if (mode === "virtualFriend" && isVirtualFriendResponse(responseData)) {
186+
trackEvent("Click", {
187+
page: "친구 저장",
188+
element: "대화 시작하기"
189+
});
185190
navigate("/chat", {
186191
state: {
187192
mbti,
@@ -190,6 +195,10 @@ const SelectInfo = () => {
190195
}
191196
});
192197
} else if (mode === "fastFriend" && typeof responseData === "number") {
198+
trackEvent("Click", {
199+
page: "빠른 대화 설정",
200+
element: "대화 시작하기"
201+
});
193202
navigate("/chat", {
194203
state: {
195204
mbti,

0 commit comments

Comments
 (0)