feat: 앱 GA4 이벤트 틀(track, 웹과 같은 이벤트 목록을 shared로) — 기존 앱 기능에 창_열기·각_보기·글_열기·로그인·지역_변경·좋아요·댓글·신고·차단·약관_동의·공유, 전송은 Firebase 연결 뒤. 탭 밖 화면용 루트 스택
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
fcc7ed804c
commit
cab3336859
20 files changed
+201
-110
No files matched your search
@@ -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' });
|
||||
}
|
||||
@@ -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]);
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in new issue
Block a user