diff --git a/docs/이벤트_추적.md b/docs/이벤트_추적.md index 0488f58..b841f35 100644 --- a/docs/이벤트_추적.md +++ b/docs/이벤트_추적.md @@ -72,7 +72,14 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 - 점수 근거·댓글창 열기처럼 창으로 여는 기능은 따로 이벤트를 두지 않고 `sheet_open`의 `sheet`로 나눠 본다. - `region_change`의 `location`은 처음 온 사람의 자동 위치 맞춤도 포함한다. - 설치는 카드 노출 → 누름 → 설치 완료 → 홈 화면 실행 순서로 본다. 아이폰은 설치 완료를 알 수 없어 `app_launch`로 대신 본다. -- 새 이벤트는 `analytics.ts`의 `Events` 타입에 먼저 더한다. 타입에 없는 이름은 빌드에서 걸린다. +- 새 이벤트는 `shared/lib/analytics.ts`의 `Events` 타입과 `GA_NAME` 에 먼저 더한다 (웹·앱이 같이 씀). 타입에 없는 이름은 빌드에서 걸린다. + +## 앱 (안드로이드, `mobile/`) + +- 앱도 같은 이벤트 이름·값으로 `track()`을 부른다 (`mobile/src/lib/analytics.ts`). 모든 이벤트에 `platform: 'app'`이 붙는다. +- **아직 GA4로 보내지 않는다 (2026-11-04).** Firebase Analytics(`google-services.json`)를 붙이면 앱 시작 때 `setAnalyticsSender`로 보내는 함수를 단다. 그 전까지 `track()`은 아무것도 보내지 않는다. 개발 빌드(`__DEV__`)는 붙인 뒤에도 보내지 않는다. +- 앱에서 부르는 곳: `sheet_open`(`components/sheets/index.tsx`), `view_gak`(`sheets/gak.tsx`), `select_content`(`sheets/article.tsx`), `login`·`sign_up`(`sheets/login.tsx`, 구글만), `region_change`(`sheets/region.tsx`·`lib/region.tsx`), `like`(`post/post-card.tsx` 글, `sheets/comments.tsx` 댓글), `comment`·`report`·`block`·`terms_agree`(`sheets/comments.tsx`), `share`(`lib/share-image.ts`). +- 앱 `share`의 `ratio`는 `'card'` — 보이는 카드를 그대로 찍어 보내 비율을 고르지 않는다. ## GA4 설정 diff --git a/frontend/src/lib/analytics.ts b/frontend/src/lib/analytics.ts index b5ac72b..eb019af 100644 --- a/frontend/src/lib/analytics.ts +++ b/frontend/src/lib/analytics.ts @@ -1,51 +1,8 @@ -import type { PinnedKey } from '../b/pinnedLike' -import type { Holiday } from '../b/holiday' +import { GA_NAME, type Events as SharedEvents } from '@nalssigak/shared/lib/analytics' import type { SheetState } from '../b/sheetContext' -/** GA4로 보내는 이벤트와 값. 목록은 docs/이벤트_추적.md */ -type Events = { - view_gak: { index_id: number; gak_name: string; score: number; rank: number } - select_content: { content_type: 'article'; item_id: number; category: string } - share: { content_type: 'image'; item_id: string; method: 'share_sheet' | 'download'; ratio: string } - login: { method: 'id' | 'google' | 'toss' } - sign_up: { method: 'id' | 'google' | 'toss' } - region_change: { region_name: string; method: 'list' | 'location' } - install_banner_view: Record - install_click: { from: 'banner' | 'menu'; method: 'prompt' | 'guide' } - install_choice: { outcome: 'accepted' | 'dismissed' } - install_done: Record - app_launch: { mode: 'standalone' } - /** index.html 첫 화면 스크립트가 gtag 로 바로 보낸다 */ - boot_stuck: { reason: string; seconds: number; tries: number; app_started: boolean } - sheet_open: { sheet: SheetType } - like: { content_type: 'post' | 'comment' | 'talk' | PinnedKey; item_id: number } - comment: { post_id: number } - talk_comment: { talk_id: number } - report: { content_type: 'comment' | 'talk'; reason: number } - block: { content_type: 'comment' | 'talk' } - terms_agree: Record - talk_post: { topic: number; with_image: boolean } - feed_item_view: { item_type: 'talk' | 'event'; position: number } - hero_day_switch: { day: 'today' | 'tomorrow' } - tomorrow_to_today: { region_name: string } - search_landing: { page: 'today' | 'tomorrow'; engine: 'google' | 'naver'; copy: 'new' | 'old' | 'none' } - shorts_open: { video_id: string } - shorts_view: { video_id: string; index: number } - shorts_sound: { on: boolean } - foliage_open: Record - foliage_spot: { spot_name: string; from: 'page' | 'card' } - my_gak_save: { gak_name: string } - fortune_draw: { card: string } - day_log: { mood: number; went_out: boolean; card_hit: boolean | null } - today_icon: { icon: string } - saju_input: { with_time: boolean } - saju_view: { scene: string; score: number; strength: string; top_element: string } - game_start: { again: boolean; logged_in: boolean; wind_ms: number; theme: 'basic' | Holiday['key'] } - game_round: { round: number; score: number; logged_in: boolean } - game_over: { round: number; score: number; best: boolean; drops: number } - toss_intro_start: Record - install_banner_close: Record -} +/** 이벤트 목록은 앱과 같이 쓴다 (shared/lib/analytics.ts, docs/이벤트_추적.md) */ +type Events = SharedEvents type SheetType = Exclude['type'] @@ -55,50 +12,6 @@ declare global { } } -/** GA 에 찍히는 이벤트 이름 (한국어). 코드에서는 왼쪽 키로 부른다 */ -const GA_NAME: Record = { - view_gak: '각_보기', - select_content: '글_열기', - share: '공유', - login: '로그인', - sign_up: '회원가입', - region_change: '지역_변경', - install_banner_view: '설치배너_노출', - install_click: '설치_누름', - install_choice: '설치_선택', - install_done: '설치_완료', - app_launch: '앱_실행', - boot_stuck: '첫화면_멈춤', - sheet_open: '창_열기', - like: '좋아요', - comment: '댓글', - talk_comment: '이야기_댓글', - report: '신고', - block: '차단', - terms_agree: '약관_동의', - talk_post: '이야기_올림', - feed_item_view: '피드_항목_노출', - hero_day_switch: '오늘내일_전환', - tomorrow_to_today: '내일에서_오늘로', - search_landing: '검색_유입', - shorts_open: '쇼츠_열기', - shorts_view: '쇼츠_보기', - shorts_sound: '쇼츠_소리', - foliage_open: '단풍지도_열기', - foliage_spot: '단풍명소_보기', - my_gak_save: '내각_저장', - fortune_draw: '타로_뽑기', - day_log: '하루_기록', - today_icon: '오늘아이콘_누름', - saju_input: '사주_입력', - saju_view: '사주_결과', - game_start: '게임_시작', - game_round: '게임_라운드', - game_over: '게임_끝', - toss_intro_start: '토스소개_시작', - install_banner_close: '설치배너_닫기', -} - export function track(event: E, params: Events[E]) { if (import.meta.env.DEV) return window.gtag?.('event', GA_NAME[event], params) diff --git a/mobile/src/app/(tabs)/_layout.tsx b/mobile/src/app/(tabs)/_layout.tsx new file mode 100644 index 0000000..803877b --- /dev/null +++ b/mobile/src/app/(tabs)/_layout.tsx @@ -0,0 +1,18 @@ +import { Tabs } from 'expo-router/tabs'; + +import { TabBar } from '@/components/tab-bar'; +import { TopBar } from '@/components/top-bar'; + +/** 아래 탭 다섯 개. 사주·게임 같은 화면은 탭 밖(루트 스택)에서 연다 */ +export default function TabsLayout() { + return ( + } screenOptions={{ header: () => , sceneStyle: { backgroundColor: 'transparent' } }}> + {/* 메인인 오늘 탭을 가운데에 */} + + + + + + + ); +} diff --git a/mobile/src/app/gak.tsx b/mobile/src/app/(tabs)/gak.tsx similarity index 100% rename from mobile/src/app/gak.tsx rename to mobile/src/app/(tabs)/gak.tsx diff --git a/mobile/src/app/index.tsx b/mobile/src/app/(tabs)/index.tsx similarity index 100% rename from mobile/src/app/index.tsx rename to mobile/src/app/(tabs)/index.tsx diff --git a/mobile/src/app/season.tsx b/mobile/src/app/(tabs)/season.tsx similarity index 100% rename from mobile/src/app/season.tsx rename to mobile/src/app/(tabs)/season.tsx diff --git a/mobile/src/app/sky.tsx b/mobile/src/app/(tabs)/sky.tsx similarity index 100% rename from mobile/src/app/sky.tsx rename to mobile/src/app/(tabs)/sky.tsx diff --git a/mobile/src/app/week.tsx b/mobile/src/app/(tabs)/week.tsx similarity index 100% rename from mobile/src/app/week.tsx rename to mobile/src/app/(tabs)/week.tsx diff --git a/mobile/src/app/_layout.tsx b/mobile/src/app/_layout.tsx index 45b2c9e..9ba94f4 100644 --- a/mobile/src/app/_layout.tsx +++ b/mobile/src/app/_layout.tsx @@ -3,7 +3,7 @@ import { BagelFatOne_400Regular } from '@expo-google-fonts/bagel-fat-one'; import { GowunBatang_400Regular } from '@expo-google-fonts/gowun-batang'; import { Jua_400Regular, useFonts } from '@expo-google-fonts/jua'; import { QueryClientProvider } from '@tanstack/react-query'; -import { Tabs } from 'expo-router/tabs'; +import { Stack } from 'expo-router'; import * as SplashScreen from 'expo-splash-screen'; import { StatusBar } from 'expo-status-bar'; import { useEffect } from 'react'; @@ -11,10 +11,8 @@ import { View } from 'react-native'; import '@/global.css'; import { SkyBg } from '@/components/sky-bg'; -import { TabBar } from '@/components/tab-bar'; import { FirstLoad } from '@/components/first-load'; import { SheetProvider } from '@/components/sheets'; -import { TopBar } from '@/components/top-bar'; import { AuthProvider } from '@/lib/auth'; import { queryClient } from '@/lib/query-client'; import { RegionProvider } from '@/lib/region'; @@ -28,14 +26,10 @@ function Shell() { - } screenOptions={{ header: () => , sceneStyle: { backgroundColor: 'transparent' } }}> - {/* 메인인 오늘 탭을 가운데에 */} - - - - - - + {/* 탭 묶음 위에 사주·게임 같은 탭 밖 화면이 쌓인다. 하늘 배경이 비치게 화면 바탕은 투명 */} + + + ); diff --git a/mobile/src/components/post/post-card.tsx b/mobile/src/components/post/post-card.tsx index 3dd2e9d..0bfc80b 100644 --- a/mobile/src/components/post/post-card.tsx +++ b/mobile/src/components/post/post-card.tsx @@ -13,6 +13,7 @@ import { LikeBurst } from '@/components/post/like-burst'; import { Dots, Pager } from '@/components/post/pager'; import { slideBg, SlideView, type Slide } from '@/components/post/slides'; import { Ic, Skel } from '@/components/ui'; +import { track } from '@/lib/analytics'; import { useAuth } from '@/lib/auth'; import { useSheet } from '@/lib/sheet'; import { shareView } from '@/lib/share-image'; @@ -157,7 +158,11 @@ function FullCard({ post }: PostProps) { (on ? like : unlike).mutate( { path: { post_id: post.post_id } }, { - onSuccess: (res) => (res.result?.success ? patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }) : revert()), + onSuccess: (res) => { + if (!res.result?.success) return revert(); + patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }); + if (on) track('like', { content_type: 'post', item_id: post.post_id }); + }, onError: revert, }, ); diff --git a/mobile/src/components/sheets/article.tsx b/mobile/src/components/sheets/article.tsx index ed193a4..b6cd3fb 100644 --- a/mobile/src/components/sheets/article.tsx +++ b/mobile/src/components/sheets/article.tsx @@ -2,11 +2,12 @@ import { getArticleOptions, getSeasonWeekOptions } from '@nalssigak/shared/api/c import { ARTICLE_LABEL, articleMeta, cardBg, dateRange, loadOf, shortDay } from '@nalssigak/shared/lib'; import { useQuery } from '@tanstack/react-query'; import { LinearGradient } from 'expo-linear-gradient'; -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { Pressable, View } from 'react-native'; import { Text } from '@/components/text'; import { Credit, Ic, StateBox, Thumb } from '@/components/ui'; +import { track } from '@/lib/analytics'; import { CARD_BG } from '@/lib/colors'; import { useSheet } from '@/lib/sheet'; import { useSky } from '@/lib/sky'; @@ -22,6 +23,13 @@ export function ArticleSheet({ articleId, onTitle }: { articleId: number; onTitl onTitle(a ? (ARTICLE_LABEL[a.category] ?? '') : ''); }, [a, onTitle]); + const tracked = useRef(0); + useEffect(() => { + if (!a || tracked.current === a.article_id) return; + tracked.current = a.article_id; + track('select_content', { content_type: 'article', item_id: a.article_id, category: ARTICLE_LABEL[a.category] ?? a.category }); + }, [a]); + const load = loadOf(q); if (!a) return {load === 'loading' ? : q.refetch()} empty="글을 찾지 못했어요." hold={} boxClassName="inset-0" />}; return ( diff --git a/mobile/src/components/sheets/comments.tsx b/mobile/src/components/sheets/comments.tsx index b3ae57c..657e519 100644 --- a/mobile/src/components/sheets/comments.tsx +++ b/mobile/src/components/sheets/comments.tsx @@ -21,6 +21,7 @@ import { Text } from '@/components/text'; import { useCSSVariable } from 'uniwind'; import { Avatar, Skel, StateBox } from '@/components/ui'; +import { track } from '@/lib/analytics'; import { useAuth } from '@/lib/auth'; import { useRegion } from '@/lib/region'; import { useSheet } from '@/lib/sheet'; @@ -59,9 +60,10 @@ function CommentMenu({ c, postId, onNotice }: { c: CommentData; postId: number; const block = useMutation(blockAuthorMutation()); const pending = report.isPending || block.isPending; - const finish = (notice: string) => ({ + const finish = (notice: string, done: () => void) => ({ onSuccess: (res: { result?: { success?: boolean } }) => { if (!res.result?.success) return setFailed(true); + done(); setStep('closed'); onNotice(notice); queryClient.invalidateQueries({ predicate: isCommentList }); @@ -90,12 +92,12 @@ function CommentMenu({ c, postId, onNotice }: { c: CommentData; postId: number; )} {step === 'report' && REPORT_REASONS.map(([reason, label]) => ( - report.mutate({ path: { comment_id: c.comment_id }, body: { reason } }, finish('신고했어요. 확인하고 조치할게요.'))} /> + report.mutate({ path: { comment_id: c.comment_id }, body: { reason } }, finish('신고했어요. 확인하고 조치할게요.', () => track('report', { content_type: 'comment', reason })))} /> ))} {step === 'block' && ( <> {c.nickname}님 댓글을 더는 안 볼까요? - block.mutate({ path: { comment_id: c.comment_id } }, finish('차단했어요. 내 정보에서 풀 수 있어요.'))} /> + block.mutate({ path: { comment_id: c.comment_id } }, finish('차단했어요. 내 정보에서 풀 수 있어요.', () => track('block', { content_type: 'comment' })))} /> go('closed')} /> )} @@ -158,6 +160,7 @@ function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; o if (res.result?.success) { setLiked(!!res.liked); if (res.like_count != null) setCount(res.like_count); + if (next) track('like', { content_type: 'comment', item_id: c.comment_id }); return; } revert(); @@ -267,6 +270,7 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin if (res.result?.desc === 'TERMS_REQUIRED') return setAskTerms(true); setAddFailed(!res.result?.success); if (!res.result?.success) return; + track('comment', { post_id: postId }); setText(''); queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) }); queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) }); @@ -290,6 +294,7 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin onSuccess: (res) => { if (!res.result?.success) return setAddFailed(true); queryClient.setQueryData(meQueryKey(), res); + track('terms_agree', {}); setAskTerms(false); send(); }, diff --git a/mobile/src/components/sheets/gak.tsx b/mobile/src/components/sheets/gak.tsx index 1bbde8f..70dc109 100644 --- a/mobile/src/components/sheets/gak.tsx +++ b/mobile/src/components/sheets/gak.tsx @@ -3,12 +3,13 @@ import type { Factor, ResIndexDetail } from '@nalssigak/shared/api/client/types. import { loadOf } from '@nalssigak/shared/lib'; import { useQuery } from '@tanstack/react-query'; import { LinearGradient } from 'expo-linear-gradient'; -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { View } from 'react-native'; import { Text } from '@/components/text'; import Svg, { Circle, Line, Polygon, Text as SvgText, TSpan } from 'react-native-svg'; import { Ic, Skel, StateBox } from '@/components/ui'; +import { track } from '@/lib/analytics'; import { useRegion } from '@/lib/region'; import { useSky } from '@/lib/sky'; @@ -110,6 +111,14 @@ export function GakSheet({ indexId, onTitle }: { indexId: number; onTitle: (t: s onTitle(g ? `${g.rank}위 ${g.name}` : '계산 근거'); }, [g, onTitle]); + // 지역이 바뀌어 다시 받아도 한 번만 보낸다 + const tracked = useRef(0); + useEffect(() => { + if (!g || tracked.current === g.index_id) return; + tracked.current = g.index_id; + track('view_gak', { index_id: g.index_id, gak_name: g.name, score: g.score, rank: g.rank }); + }, [g]); + const load = loadOf(q); if (!g) return {load === 'loading' ? : q.refetch()} empty="이 각의 계산 근거가 아직 없어요." hold={} boxClassName="inset-0" />}; const factors = d.factors ?? []; diff --git a/mobile/src/components/sheets/index.tsx b/mobile/src/components/sheets/index.tsx index 046cde0..5e1c64d 100644 --- a/mobile/src/components/sheets/index.tsx +++ b/mobile/src/components/sheets/index.tsx @@ -5,6 +5,7 @@ import { Text } from '@/components/text'; import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from 'react-native-reanimated'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { track } from '@/lib/analytics'; import { SheetContext, useSheet, type SheetState } from '@/lib/sheet'; import { ArticleSheet, SeasonWeekSheet } from './article'; @@ -16,7 +17,10 @@ import { RegionSheet } from './region'; export function SheetProvider({ children }: { children: ReactNode }) { const [state, setState] = useState(null); - const open = useCallback((s: Exclude) => setState(s), []); + const open = useCallback((s: Exclude) => { + track('sheet_open', { sheet: s.type }); + setState(s); + }, []); const close = useCallback(() => setState(null), []); const api = useMemo(() => ({ open, close }), [open, close]); diff --git a/mobile/src/components/sheets/login.tsx b/mobile/src/components/sheets/login.tsx index a9d1e58..8c080c1 100644 --- a/mobile/src/components/sheets/login.tsx +++ b/mobile/src/components/sheets/login.tsx @@ -4,6 +4,7 @@ import { useState } from 'react'; import { Pressable } from 'react-native'; import { Text } from '@/components/text'; +import { track } from '@/lib/analytics'; import { useAuth } from '@/lib/auth'; import { GoogleButton } from './google'; @@ -20,6 +21,7 @@ export function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLogge return; } setTokens(res.access_token, res.refresh_token ?? null); + track(res.is_new ? 'sign_up' : 'login', { method: 'google' }); onLoggedIn(); }; const fail = () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.'); diff --git a/mobile/src/components/sheets/region.tsx b/mobile/src/components/sheets/region.tsx index 20927bf..9d5b9d9 100644 --- a/mobile/src/components/sheets/region.tsx +++ b/mobile/src/components/sheets/region.tsx @@ -6,6 +6,7 @@ import { Pressable, View } from 'react-native'; import { Text } from '@/components/text'; import { Skel, StateBox } from '@/components/ui'; +import { track } from '@/lib/analytics'; import { useAuth } from '@/lib/auth'; import { useRegion } from '@/lib/region'; import { useSheet } from '@/lib/sheet'; @@ -66,6 +67,7 @@ export function RegionSheet({ onDone }: { onDone: () => void }) { accessibilityState={{ selected: here }} onPress={() => { setRegion(r); + track('region_change', { region_name: r.name, method: 'list' }); onDone(); }} className="flex-row items-center justify-between border-b-[1.5px] border-line px-1 py-3" diff --git a/mobile/src/lib/analytics.ts b/mobile/src/lib/analytics.ts new file mode 100644 index 0000000..37df65b --- /dev/null +++ b/mobile/src/lib/analytics.ts @@ -0,0 +1,20 @@ +import { GA_NAME, type Events as SharedEvents } from '@nalssigak/shared/lib/analytics'; + +import type { SheetState } from '@/lib/sheet'; + +/** 이벤트 목록은 웹과 같이 쓴다 (shared/lib/analytics.ts, docs/이벤트_추적.md) */ +type Events = SharedEvents['type']>; + +type Sender = (name: string, params: Record) => void; + +let sender: Sender | null = null; + +/** GA4 로 실제로 보내는 함수를 단다. Firebase Analytics(google-services.json)를 붙이면 앱 시작 때 부른다. 그 전에는 보내지 않는다 */ +export function setAnalyticsSender(next: Sender | null) { + sender = next; +} + +export function track(event: E, params: Events[E]) { + if (__DEV__) return; + sender?.(GA_NAME[event], { ...params, platform: 'app' }); +} diff --git a/mobile/src/lib/region.tsx b/mobile/src/lib/region.tsx index a852dac..dfcfb10 100644 --- a/mobile/src/lib/region.tsx +++ b/mobile/src/lib/region.tsx @@ -5,6 +5,8 @@ import * as Location from 'expo-location'; import * as SecureStore from 'expo-secure-store'; import { createContext, use, useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'; +import { track } from '@/lib/analytics'; + const KEY = 'nalssigak.region'; export type LocateStatus = 'idle' | 'locating' | 'denied' | 'error'; @@ -67,6 +69,7 @@ export function RegionProvider({ children }: { children: ReactNode }) { if (r === 'denied') return setLocateStatus('denied'); setLocateStatus('idle'); setRegion(r); + track('region_change', { region_name: r.name, method: 'location' }); onFound?.(); }) .catch((e: unknown) => { @@ -81,7 +84,11 @@ export function RegionProvider({ children }: { children: ReactNode }) { useEffect(() => { if (stored) return; findNearest() - .then((r) => r !== 'denied' && setRegion(r)) + .then((r) => { + if (r === 'denied') return; + setRegion(r); + track('region_change', { region_name: r.name, method: 'location' }); + }) .catch((e: unknown) => console.warn('첫 위치로 지역을 찾지 못함', e)) .finally(() => setLocateStatus('idle')); }, [stored, setRegion]); diff --git a/mobile/src/lib/share-image.ts b/mobile/src/lib/share-image.ts index 50a93d1..9de6574 100644 --- a/mobile/src/lib/share-image.ts +++ b/mobile/src/lib/share-image.ts @@ -3,12 +3,16 @@ import type { RefObject } from 'react'; import { Share, type View } from 'react-native'; import { captureRef } from 'react-native-view-shot'; +import { track } from '@/lib/analytics'; + /** 보이는 화면 조각을 PNG로 찍어 공유. 이미지 공유가 안 되는 곳(웹 등)이면 글로 보낸다 */ export async function shareView(ref: RefObject, { title, message }: { title: string; message: string }) { try { if (ref.current && (await Sharing.isAvailableAsync())) { const uri = await captureRef(ref, { format: 'png', quality: 1, result: 'tmpfile' }); await Sharing.shareAsync(uri, { mimeType: 'image/png', UTI: 'public.png', dialogTitle: title }); + // 앱은 보이는 카드를 그대로 찍어 보내므로 비율은 'card' + track('share', { content_type: 'image', item_id: title, method: 'share_sheet', ratio: 'card' }); return; } await Share.share({ message }); diff --git a/shared/lib/analytics.ts b/shared/lib/analytics.ts new file mode 100644 index 0000000..73bf72c --- /dev/null +++ b/shared/lib/analytics.ts @@ -0,0 +1,93 @@ +/** 히어로·오늘의 각·단풍 지도·띠처럼 포스트 틀이 아닌 카드 (피드 응답의 반응 칸 이름) */ +export type PinnedKey = 'hero_post' | 'gak_post' | 'foliage_post' | 'events_post' | 'season_post' + +export type HolidayKey = 'halloween' | 'pepero' | 'christmas' | 'chuseok' + +/** GA4로 보내는 이벤트와 값 (웹·앱 같이 씀). 목록은 docs/이벤트_추적.md. Sheet 는 화면마다 다른 창 이름 */ +export type Events = { + view_gak: { index_id: number; gak_name: string; score: number; rank: number } + select_content: { content_type: 'article'; item_id: number; category: string } + share: { content_type: 'image'; item_id: string; method: 'share_sheet' | 'download'; ratio: string } + login: { method: 'id' | 'google' | 'toss' } + sign_up: { method: 'id' | 'google' | 'toss' } + region_change: { region_name: string; method: 'list' | 'location' } + install_banner_view: Record + install_click: { from: 'banner' | 'menu'; method: 'prompt' | 'guide' } + install_choice: { outcome: 'accepted' | 'dismissed' } + install_done: Record + app_launch: { mode: 'standalone' } + /** index.html 첫 화면 스크립트가 gtag 로 바로 보낸다 */ + boot_stuck: { reason: string; seconds: number; tries: number; app_started: boolean } + sheet_open: { sheet: Sheet } + like: { content_type: 'post' | 'comment' | 'talk' | PinnedKey; item_id: number } + comment: { post_id: number } + talk_comment: { talk_id: number } + report: { content_type: 'comment' | 'talk'; reason: number } + block: { content_type: 'comment' | 'talk' } + terms_agree: Record + talk_post: { topic: number; with_image: boolean } + feed_item_view: { item_type: 'talk' | 'event'; position: number } + hero_day_switch: { day: 'today' | 'tomorrow' } + tomorrow_to_today: { region_name: string } + search_landing: { page: 'today' | 'tomorrow'; engine: 'google' | 'naver'; copy: 'new' | 'old' | 'none' } + shorts_open: { video_id: string } + shorts_view: { video_id: string; index: number } + shorts_sound: { on: boolean } + foliage_open: Record + foliage_spot: { spot_name: string; from: 'page' | 'card' } + my_gak_save: { gak_name: string } + fortune_draw: { card: string } + day_log: { mood: number; went_out: boolean; card_hit: boolean | null } + today_icon: { icon: string } + saju_input: { with_time: boolean } + saju_view: { scene: string; score: number; strength: string; top_element: string } + game_start: { again: boolean; logged_in: boolean; wind_ms: number; theme: 'basic' | HolidayKey } + game_round: { round: number; score: number; logged_in: boolean } + game_over: { round: number; score: number; best: boolean; drops: number } + toss_intro_start: Record + install_banner_close: Record +} + +/** GA 에 찍히는 이벤트 이름 (한국어). 코드에서는 왼쪽 키로 부른다 */ +export const GA_NAME: Record = { + view_gak: '각_보기', + select_content: '글_열기', + share: '공유', + login: '로그인', + sign_up: '회원가입', + region_change: '지역_변경', + install_banner_view: '설치배너_노출', + install_click: '설치_누름', + install_choice: '설치_선택', + install_done: '설치_완료', + app_launch: '앱_실행', + boot_stuck: '첫화면_멈춤', + sheet_open: '창_열기', + like: '좋아요', + comment: '댓글', + talk_comment: '이야기_댓글', + report: '신고', + block: '차단', + terms_agree: '약관_동의', + talk_post: '이야기_올림', + feed_item_view: '피드_항목_노출', + hero_day_switch: '오늘내일_전환', + tomorrow_to_today: '내일에서_오늘로', + search_landing: '검색_유입', + shorts_open: '쇼츠_열기', + shorts_view: '쇼츠_보기', + shorts_sound: '쇼츠_소리', + foliage_open: '단풍지도_열기', + foliage_spot: '단풍명소_보기', + my_gak_save: '내각_저장', + fortune_draw: '타로_뽑기', + day_log: '하루_기록', + today_icon: '오늘아이콘_누름', + saju_input: '사주_입력', + saju_view: '사주_결과', + game_start: '게임_시작', + game_round: '게임_라운드', + game_over: '게임_끝', + toss_intro_start: '토스소개_시작', + install_banner_close: '설치배너_닫기', +}