feat: 앱 GA4 이벤트 틀(track, 웹과 같은 이벤트 목록을 shared로) — 기존 앱 기능에 창_열기·각_보기·글_열기·로그인·지역_변경·좋아요·댓글·신고·차단·약관_동의·공유, 전송은 Firebase 연결 뒤. 탭 밖 화면용 루트 스택

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
skkimandClaude committed 2026-11-04 16:52:08 +09:00
1 parent fcc7ed804c
commit cab3336859
20 files changed
+201 -110

No files matched your search

+18
View File
@@ -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 (
<Tabs initialRouteName="index" tabBar={(props) => <TabBar {...props} />} screenOptions={{ header: () => <TopBar />, sceneStyle: { backgroundColor: 'transparent' } }}>
{/* 메인인 오늘 탭을 가운데에 */}
<Tabs.Screen name="sky" />
<Tabs.Screen name="gak" />
<Tabs.Screen name="index" />
<Tabs.Screen name="week" />
<Tabs.Screen name="season" />
</Tabs>
);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+5 -11
View File
@@ -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() {
<View className="flex-1">
<SkyBg />
<StatusBar style={kind === 'night' ? 'light' : 'dark'} />
<Tabs initialRouteName="index" tabBar={(props) => <TabBar {...props} />} screenOptions={{ header: () => <TopBar />, sceneStyle: { backgroundColor: 'transparent' } }}>
{/* 메인인 오늘 탭을 가운데에 */}
<Tabs.Screen name="sky" />
<Tabs.Screen name="gak" />
<Tabs.Screen name="index" />
<Tabs.Screen name="week" />
<Tabs.Screen name="season" />
</Tabs>
{/* 탭 묶음 위에 사주·게임 같은 탭 밖 화면이 쌓인다. 하늘 배경이 비치게 화면 바탕은 투명 */}
<Stack screenOptions={{ headerShown: false, contentStyle: { backgroundColor: 'transparent' } }}>
<Stack.Screen name="(tabs)" />
</Stack>
<FirstLoad />
</View>
);
+6 -1
View File
@@ -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,
},
);
+9 -1
View File
@@ -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 <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="글을 찾지 못했어요." hold={<ArticleSkel />} boxClassName="inset-0" />}</Body>;
return (
+8 -3
View File
@@ -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]) => (
<Chip key={reason} label={label} disabled={pending} onPress={() => report.mutate({ path: { comment_id: c.comment_id }, body: { reason } }, finish('신고했어요. 확인하고 조치할게요.'))} />
<Chip key={reason} label={label} disabled={pending} onPress={() => report.mutate({ path: { comment_id: c.comment_id }, body: { reason } }, finish('신고했어요. 확인하고 조치할게요.', () => track('report', { content_type: 'comment', reason })))} />
))}
{step === 'block' && (
<>
<Text className="w-full text-[13px] font-bold text-ink">{c.nickname}님 댓글을 더는 안 볼까요?</Text>
<Chip label="차단하기" danger disabled={pending} onPress={() => block.mutate({ path: { comment_id: c.comment_id } }, finish('차단했어요. 내 정보에서 풀 수 있어요.'))} />
<Chip label="차단하기" danger disabled={pending} onPress={() => block.mutate({ path: { comment_id: c.comment_id } }, finish('차단했어요. 내 정보에서 풀 수 있어요.', () => track('block', { content_type: 'comment' })))} />
<Chip label="취소" disabled={pending} onPress={() => 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();
},
+10 -1
View File
@@ -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 <Body>{load === 'loading' ? <GakSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이 각의 계산 근거가 아직 없어요." hold={<GakSkel />} boxClassName="inset-0" />}</Body>;
const factors = d.factors ?? [];
+5 -1
View File
@@ -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<SheetState>(null);
const open = useCallback((s: Exclude<SheetState, null>) => setState(s), []);
const open = useCallback((s: Exclude<SheetState, null>) => {
track('sheet_open', { sheet: s.type });
setState(s);
}, []);
const close = useCallback(() => setState(null), []);
const api = useMemo(() => ({ open, close }), [open, close]);
+2
View File
@@ -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('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.');
+2
View File
@@ -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"
+20
View File
@@ -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<Exclude<SheetState, null>['type']>;
type Sender = (name: string, params: Record<string, unknown>) => void;
let sender: Sender | null = null;
/** GA4 로 실제로 보내는 함수를 단다. Firebase Analytics(google-services.json)를 붙이면 앱 시작 때 부른다. 그 전에는 보내지 않는다 */
export function setAnalyticsSender(next: Sender | null) {
sender = next;
}
export function track<E extends keyof Events>(event: E, params: Events[E]) {
if (__DEV__) return;
sender?.(GA_NAME[event], { ...params, platform: 'app' });
}
+8 -1
View File
@@ -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]);
+4
View File
@@ -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<View | null>, { 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 });