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

[SP1] 앰플리튜드 이벤트 트래킹 - 어바웃, 솝티클 #200

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions src/lib/constants/about.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RecordTitleType } from '@src/lib/types/about';

export const RECORD_TITLE: RecordTitleType = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한글로 타입 및 레코드를 만들면 번들링할 때 다시 영어로 바꿔주나요 ..!?? 그것이 궁금합니다!!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 GPT 선생님이 아니라고 하는데 관련된 정확한 문서를 못찾겠네요... 더 찾아보겠습니다!

'활동 멤버': 'member',
프로젝트: 'project',
스터디: 'study',
};
5 changes: 5 additions & 0 deletions src/lib/types/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ export interface AboutAPI {
getMemberInfo(part?: Part): Promise<GetMembersInfoResponse>;
getStudyInfo(generation?: number): Promise<GetStudyInfoResponse>;
}

export type RecordTitle = '활동 멤버' | '프로젝트' | '스터디';
export type RecordTitleType = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Record<RecordTitle, string>
으로도 작성할 수 있어요!!

Record 타입을 사용하면 key에 있는 값들이 모두 담겨야 타입이 완성되어서 편리합니다!~!!

[key in RecordTitle]: 'member' | 'project' | 'study';
};
10 changes: 8 additions & 2 deletions src/views/AboutPage/components/Cirriculum/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { track } from '@amplitude/analytics-browser';
import Image from 'next/image';
import { useState } from 'react';
import Flex from '@src/components/common/Flex';
import { Part } from '@src/lib/types/universal';
import { TabType, Part } from '@src/lib/types/universal';
import { parsePartToKorean } from '@src/lib/utils/parsePartToKorean';
import TabBar from '../../common/TabBar';
import * as St from './style';
Expand All @@ -13,9 +14,14 @@ type CirriculumContentProps = {
const CirriculumContent = ({ cirriculums }: CirriculumContentProps) => {
const [currentPart, setCurrentPart] = useState(Part.PLAN);

const handleTabClick = (tab: TabType) => {
setCurrentPart(tab.value);
track('click_about_part', { part: tab.label });
};

return (
<Flex dir="column" gap={{ mobile: 18, tablet: 24, desktop: 48 }}>
<TabBar onTabClick={setCurrentPart} selectedTab={currentPart} includesExtra={false} />
<TabBar onTabClick={handleTabClick} selectedTab={currentPart} includesExtra={false} />
<St.ImageWrapper>
<Image
src={cirriculums[currentPart]}
Expand Down
9 changes: 7 additions & 2 deletions src/views/AboutPage/components/Member/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { track } from '@amplitude/analytics-browser';
import { useMemo, useState } from 'react';
import DataErrorBanner from '@src/components/DataErrorBanner';
import Flex from '@src/components/common/Flex';
import { ExtraPart } from '@src/lib/types/universal';
import { ExtraPart, ExtraTabType } from '@src/lib/types/universal';
import { PartExtraType } from '@src/lib/types/universal';
import { emptyMembers } from '@src/views/AboutPage/constant/emptyMembers';
import useFetchMember from '@src/views/AboutPage/hooks/useFetchMemeber';
Expand All @@ -18,8 +19,12 @@ const MemberContent = () => {
const state = useFetchMember(currentPart);

const errorContent = state._TAG === 'ERROR' && <DataErrorBanner />;
const handleTabClick = (tab: ExtraTabType) => {
setCurrentPart(tab.value);
track('click_about_member_part', { part: tab.label });
};
const tabBarContent = !(state._TAG === 'ERROR' && shouldNotShownWithError) && (
<TabBar onTabClick={setCurrentPart} selectedTab={currentPart} includesExtra={true} />
<TabBar onTabClick={handleTabClick} selectedTab={currentPart} includesExtra={true} />
);
const cardContent = useMemo(() => {
if (state._TAG === 'OK')
Expand Down
11 changes: 9 additions & 2 deletions src/views/AboutPage/components/Record/Item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { track } from '@amplitude/analytics-browser';
import Flex from '@src/components/common/Flex';
import NumberRoller from '@src/components/common/NumberRoller';
import { RECORD_TITLE } from '@src/lib/constants/about';
import { RecordTitle } from '@src/lib/types/about';
import * as St from './style';

type RecordItemProps = {
href: string;
title: string;
title: RecordTitle;
countNumber?: number;
countString?: string;
};

const RecordItem = (props: RecordItemProps) => {
const trackRecordClick = () => {
track(`click_about_${RECORD_TITLE[props.title]}`);
};

return (
<St.LinkWrapper href={props.href}>
<St.LinkWrapper href={props.href} onClick={trackRecordClick}>
<Flex
dir="column"
gap={{ mobile: 4, tablet: 8, desktop: 8 }}
Expand Down
10 changes: 5 additions & 5 deletions src/views/AboutPage/components/common/TabBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { extraTabs, tabs } from '@src/lib/constants/tabs';
import { ExtraPart, Part } from '@src/lib/types/universal';
import { ExtraPart, ExtraTabType, Part, TabType } from '@src/lib/types/universal';
import * as St from './style';

type TabBarPropsIncludedExtra = {
includesExtra: true;
selectedTab: ExtraPart;
onTabClick(targetTab: ExtraPart): void;
onTabClick(tab: ExtraTabType): void;
};
type TabBarPropsNoExtra = {
includesExtra: false;
selectedTab: Part;
onTabClick(targetTab: Part): void;
onTabClick(tab: TabType): void;
};
type TabBarProps = TabBarPropsIncludedExtra | TabBarPropsNoExtra;

Expand All @@ -21,7 +21,7 @@ const TabBar = ({ includesExtra, onTabClick, selectedTab }: TabBarProps) => {
{extraTabs.map((tab) => (
<Tab
key={tab.value}
onClick={() => onTabClick(tab.value)}
onClick={() => onTabClick(tab)}
label={tab.label}
selected={selectedTab === tab.value}
/>
Expand All @@ -34,7 +34,7 @@ const TabBar = ({ includesExtra, onTabClick, selectedTab }: TabBarProps) => {
{tabs.map((tab) => (
<Tab
key={tab.value}
onClick={() => onTabClick(tab.value)}
onClick={() => onTabClick(tab)}
label={tab.label}
selected={selectedTab === tab.value}
/>
Expand Down
10 changes: 8 additions & 2 deletions src/views/SopticlePage/components/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { track } from '@amplitude/analytics-browser';
import { useState } from 'react';
import { ExtraPart, PartExtraType } from '@src/lib/types/universal';
import { ExtraPart, ExtraTabType, PartExtraType } from '@src/lib/types/universal';
import Sopticles from '../Sopticles';
import TabBar from '../TabBar';

const Content = () => {
const [selectedTab, setSelectedTab] = useState<ExtraPart>(PartExtraType.ALL);

const handleTabClick = (tab: ExtraTabType) => {
setSelectedTab(tab.value);
track('click_sopticle_part', { part: tab.label });
};

return (
<>
<TabBar onTabClick={setSelectedTab} selectedTab={selectedTab} />
<TabBar onTabClick={handleTabClick} selectedTab={selectedTab} />
<Sopticles selectedTab={selectedTab} />
</>
);
Expand Down
9 changes: 8 additions & 1 deletion src/views/SopticlePage/components/Sopticles/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { track } from '@amplitude/analytics-browser';
import { useState } from 'react';
import { ReactComponent as IconHeartFilled } from '@src/assets/icons/ic_heartfilled.svg';
import { ReactComponent as IconHeartUnfilled } from '@src/assets/icons/ic_heartunfilled.svg';
Expand All @@ -22,14 +23,20 @@ const SopticleCard = ({ sopticle }: SopticleCardProps) => {
e.preventDefault();
const response = await api.sopticleAPI.postSopticleLike(sopticle.id, liked ?? true);
setLiked(response.currentLike);
track('click_sopticle_like', { sopticle_id: sopticle.id, is_like: response.currentLike });
if (response.likeChanged)
setLikesCount((prevLikesCount) =>
response.currentLike ? prevLikesCount + 1 : prevLikesCount - 1,
);
};

return (
<S.Card href={sopticle.link} target="_blank" passHref>
<S.Card
href={sopticle.link}
target="_blank"
passHref
onClick={() => track('click_sopticle_detail', { sopticle_id: sopticle.id })}
>
<S.ThumbnailWrapper>
<S.Thumbnail src={sopticle.thumbnail} alt={sopticle.title} fill />
<S.ChipWrapper>
Expand Down
4 changes: 2 additions & 2 deletions src/views/SopticlePage/components/TabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as S from './style';

type TabBarProps = {
selectedTab: ExtraPart;
onTabClick(targetTab: ExtraPart): void;
onTabClick(tab: ExtraTabType): void;
};

const TabBar = ({ onTabClick, selectedTab }: TabBarProps) => {
Expand All @@ -13,7 +13,7 @@ const TabBar = ({ onTabClick, selectedTab }: TabBarProps) => {
{extraTabs.map((tab) => (
<Tab
key={tab.value}
onClick={() => onTabClick(tab.value)}
onClick={() => onTabClick(tab)}
tab={tab}
selected={selectedTab === tab.value}
/>
Expand Down
Loading