From 442441931f00c124f71936c9a6ecf63aa760eb53 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 30 Oct 2026 11:49:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EA=B5=AC=EA=B8=80=C2=B7=ED=86=A0?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EC=B2=98=EC=9D=8C=20=EB=93=A4=EC=96=B4?= =?UTF-8?q?=EC=99=80=20=EA=B3=84=EC=A0=95=EC=9D=B4=20=EC=83=9D=EA=B8=B0?= =?UTF-8?q?=EB=A9=B4=20GA=20sign=5Fup=20=E2=80=94=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20is=5Fnew,=20=EB=8B=A4=EC=8B=9C=20=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EC=98=A4=EB=A9=B4=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/router/v1/auth/account.py | 14 ++++++------ backend/router/v1/auth/protocol.py | 1 + backend/services/auth_service.py | 34 +++++++++++++++++------------- backend/tests/test_auth_toss.py | 18 ++++++++++++++++ docs/이벤트_추적.md | 6 +++--- frontend/src/b/Sheets.tsx | 6 ++++-- frontend/src/lib/analytics.ts | 2 +- shared/api/client/types.gen.ts | 6 ++++++ 8 files changed, 59 insertions(+), 28 deletions(-) diff --git a/backend/router/v1/auth/account.py b/backend/router/v1/auth/account.py index 92ac35d..b5c1599 100644 --- a/backend/router/v1/auth/account.py +++ b/backend/router/v1/auth/account.py @@ -21,17 +21,17 @@ def _me(u: User) -> Me: return Me(login_id=u.login_id, nickname=u.nickname, character=u.character, color=u.color, mood=u.mood, provider=AuthProvider(u.provider), terms_agreed=u.terms_agreed_at is not None) -def _auth(err: ErrorType, user, service: AuthService) -> Res_Auth: +def _auth(err: ErrorType, user, service: AuthService, is_new: bool = False) -> Res_Auth: if err is not ErrorType.SUCCESS: return Res_Auth(result=error_info(err)) access, refresh = service.tokens(user) - return Res_Auth(access_token=access, refresh_token=refresh, me=_me(user)) + return Res_Auth(access_token=access, refresh_token=refresh, me=_me(user), is_new=is_new) @router.post("/signup", response_model=Res_Auth, response_model_exclude_none=True, summary="회원가입 (아이디 영문 소문자·숫자·_ 4~20자, 비밀번호 8자 이상, 닉네임 2~12자)") async def signup(req: Req_Signup, service: AuthService = Depends()) -> Res_Auth: err, user = await service.signup(req.login_id, req.password, req.nickname.strip()) - return _auth(err, user, service) + return _auth(err, user, service, is_new=True) @router.post("/login", response_model=Res_Auth, response_model_exclude_none=True, summary="로그인") @@ -42,8 +42,8 @@ async def login(req: Req_Login, service: AuthService = Depends()) -> Res_Auth: @router.post("/toss", response_model=Res_Auth, response_model_exclude_none=True, summary="토스 로그인 (앱인토스 TossAuth.login 의 authorizationCode·referrer)") async def toss(req: Req_TossLogin, service: AuthService = Depends()) -> Res_Auth: - err, user = await service.toss_login(req.authorization_code, req.referrer) - return _auth(err, user, service) + err, user, created = await service.toss_login(req.authorization_code, req.referrer) + return _auth(err, user, service, is_new=created) def _check_toss_basic(authorization: Optional[str]) -> None: @@ -68,8 +68,8 @@ async def toss_unlink(req: Req_TossUnlink, authorization: Optional[str] = Header @router.post("/google", response_model=Res_Auth, response_model_exclude_none=True, summary="구글 로그인 (처음이면 자동 닉네임으로 가입)") async def google_login(req: Req_Google, service: AuthService = Depends()) -> Res_Auth: - err, user = await service.google(req.credential) - return _auth(err, user, service) + err, user, created = await service.google(req.credential) + return _auth(err, user, service, is_new=created) @router.get("/config", response_model=Res_AuthConfig, response_model_exclude_none=True, summary="로그인 화면 설정 (구글 클라이언트 ID)") diff --git a/backend/router/v1/auth/protocol.py b/backend/router/v1/auth/protocol.py index 5c34c84..6509a05 100644 --- a/backend/router/v1/auth/protocol.py +++ b/backend/router/v1/auth/protocol.py @@ -55,6 +55,7 @@ class Res_Auth(Res_WebPacketProtocol): access_token: Optional[str] = None refresh_token: Optional[str] = None me: Optional[Me] = None + is_new: Optional[bool] = Field(None, description="이번 요청으로 새로 가입한 계정이면 true (GA sign_up)") class Res_TossUnlink(Res_WebPacketProtocol): diff --git a/backend/services/auth_service.py b/backend/services/auth_service.py index f2cc309..085fb35 100644 --- a/backend/services/auth_service.py +++ b/backend/services/auth_service.py @@ -61,19 +61,20 @@ class AuthService: return ErrorType.AUTH_FAILED, None return ErrorType.SUCCESS, user - async def toss_login(self, authorization_code: str, referrer: str) -> tuple[ErrorType, Optional[User]]: - """토스 userKey 로 계정을 찾고, 없으면 만든다. 이름·전화번호 같은 개인정보는 받지 않는다.""" + async def toss_login(self, authorization_code: str, referrer: str) -> tuple[ErrorType, Optional[User], bool]: + """토스 userKey 로 계정을 찾고, 없으면 만든다(셋째 값 True = 이번에 가입). 이름·전화번호 같은 개인정보는 받지 않는다.""" if not authorization_code or referrer not in TOSS_REFERRERS: - return ErrorType.INVALID_INPUT, None + return ErrorType.INVALID_INPUT, None, False try: key = str(await toss_login.user_key(authorization_code, referrer)) except toss_login.TossLoginError as e: LOG.error(f"[auth] toss login: {e}") - return ErrorType.AUTH_FAILED, None + return ErrorType.AUTH_FAILED, None, False provider = AuthProvider.TOSS.value err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_provider_uid(s, provider, key)) if err is not ErrorType.SUCCESS: - return err, None + return err, None, False + created = user is None if user is None: err, user = await DB_SESSION_MNG.execute_lambda_write( lambda s: self.crud.create_social(s, provider, key, f"toss_{key}", f"토스{key[-4:]}") @@ -82,30 +83,33 @@ class AuthService: # 같은 사람이 동시에 두 번 들어온 경우 먼저 만든 계정을 쓴다 err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_provider_uid(s, provider, key)) if err is not ErrorType.SUCCESS or user is None: - return err if err is not ErrorType.SUCCESS else ErrorType.DB_ERROR, None + return err if err is not ErrorType.SUCCESS else ErrorType.DB_ERROR, None, False + created = False if user.status != 1: - return ErrorType.AUTH_FAILED, None - return ErrorType.SUCCESS, user + return ErrorType.AUTH_FAILED, None, False + return ErrorType.SUCCESS, user, created - async def google(self, credential: str) -> tuple[ErrorType, Optional[User]]: - """구글 ID 토큰으로 로그인. 처음이면 자동 닉네임으로 계정을 만든다. 구글 이름·이메일은 저장하지 않는다.""" + async def google(self, credential: str) -> tuple[ErrorType, Optional[User], bool]: + """구글 ID 토큰으로 로그인. 처음이면 자동 닉네임으로 계정을 만든다(셋째 값 True = 이번에 가입). 구글 이름·이메일은 저장하지 않는다.""" sub = await verify_google(credential) if sub is None: - return ErrorType.AUTH_FAILED, None + return ErrorType.AUTH_FAILED, None, False login_id = f"google_{sub}" err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_login_id(s, login_id)) if err is not ErrorType.SUCCESS: - return err, None + return err, None, False + created = user is None if user is None: err, user = await DB_SESSION_MNG.execute_lambda_write(lambda s: self.crud.create_google(s, sub, auto_nickname())) if err is not ErrorType.SUCCESS: # 같은 계정이 동시에 처음 들어온 경우엔 먼저 만들어진 쪽을 쓴다 err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_login_id(s, login_id)) if err is not ErrorType.SUCCESS or user is None: - return ErrorType.DB_ERROR, None + return ErrorType.DB_ERROR, None, False + created = False if user.status != 1: - return ErrorType.AUTH_FAILED, None - return ErrorType.SUCCESS, user + return ErrorType.AUTH_FAILED, None, False + return ErrorType.SUCCESS, user, created async def toss_unlink(self, user_key: str) -> ErrorType: """토스에서 연결을 끊으면 그 계정의 모든 토큰을 무효로 만든다. 계정이 없어도 성공으로 본다.""" diff --git a/backend/tests/test_auth_toss.py b/backend/tests/test_auth_toss.py index 78587b8..d2b9f80 100644 --- a/backend/tests/test_auth_toss.py +++ b/backend/tests/test_auth_toss.py @@ -85,3 +85,21 @@ def test_success_reads_toss_wrapper(): toss_login._success(fail, "login-me") with pytest.raises(toss_login.TossLoginError, match="invalid_grant"): toss_login._success(grant, "generate-token") + + +@pytest.mark.anyio +async def test_toss_login_marks_only_first_as_new(monkeypatch): + """처음 들어온 요청만 is_new(GA sign_up), 같은 사람이 다시 들어오면 로그인""" + import secrets + + key = 10_000_000 + secrets.randbelow(80_000_000) + + async def fake_user_key(code: str, referrer: str) -> int: + return key + + monkeypatch.setattr(toss_login, "user_key", fake_user_key) + async with client() as c: + first = (await c.post("/v1/auth/toss", json={"authorization_code": "code-x", "referrer": "DEFAULT"})).json() + again = (await c.post("/v1/auth/toss", json={"authorization_code": "code-x", "referrer": "DEFAULT"})).json() + assert first["result"]["success"] is True and first["is_new"] is True + assert again["result"]["success"] is True and again["is_new"] is False diff --git a/docs/이벤트_추적.md b/docs/이벤트_추적.md index 86c3500..ebfe8b9 100644 --- a/docs/이벤트_추적.md +++ b/docs/이벤트_추적.md @@ -26,8 +26,8 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 | `view_gak` | 각 상세 시트가 열려 데이터가 뜸 (같은 각은 한 번만) | `index_id`, `gak_name`, `score`, `rank` | `Sheets.tsx` `GakSheet` | | `select_content` | 글 시트가 열려 데이터가 뜸 (같은 글은 한 번만) | `content_type: 'article'`, `item_id`(글 번호), `category`(분류 이름) | `Sheets.tsx` `ArticleSheet` | | `share` | 공유창으로 보내기 성공, 또는 이미지 내려받기 | `content_type: 'image'`, `item_id`(공유 제목), `method: 'share_sheet' \| 'download'`, `ratio`(이미지 비율) | `Sheets.tsx` `ShareSheet` `send` | -| `login` | 로그인 성공 (구글로 처음 들어와 자동 가입된 경우도 `login`) | `method: 'id' \| 'google' \| 'toss'`(앱인토스) | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | -| `sign_up` | 가입 성공 | `method: 'id'` | `Sheets.tsx` `LoginSheet` `done` | +| `login` | 로그인 성공 (이미 있던 계정) | `method: 'id' \| 'google' \| 'toss'`(앱인토스) | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | +| `sign_up` | 가입 성공 (구글·토스로 처음 들어와 계정이 새로 생김, 서버 응답 `is_new`) | `method: 'id' \| 'google' \| 'toss'` | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | | `region_change` | 지역 목록에서 고름, 또는 위치로 가까운 구를 찾음 | `region_name`, `method: 'list' \| 'location'` | `Sheets.tsx` `RegionSheet`, `region.tsx` `findNearest` | | `install_banner_view` | 오늘 탭의 '홈 화면에 추가' 카드가 보임 (설치할 수 있는 곳에서, 닫은 지 2주 안 지났으면 안 보임) | 없음 | `installBanner.tsx` `InstallBanner` | | `install_click` | '홈 화면에 추가'를 누름 | `from: 'banner' \| 'menu'`(카드·내 정보 메뉴), `method: 'prompt' \| 'guide'`(설치창을 띄움·기기별 안내를 염) | `install.ts` `useInstall` | @@ -65,7 +65,7 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 - 공유창에서 사용자가 취소하면 `share`를 보내지 않는다. - 구름 합치기 게임 방법 창은 `sheet_open`(`sheet: 'gameHelp'`)으로 잡혀 따로 보내지 않는다. -- 토스판은 로그인이 없어 `login` `toss`는 나가지 않는다. `id`·`sign_up`도 지금 화면에 아이디 가입이 없어 나가지 않는다. +- 가입·로그인은 둘 중 하나만 나간다: 처음이면 `sign_up`, 다시 들어오면 `login`. `id` 는 지금 화면에 아이디 가입·로그인이 없어 나가지 않는다. - 점수 근거·댓글창 열기처럼 창으로 여는 기능은 따로 이벤트를 두지 않고 `sheet_open`의 `sheet`로 나눠 본다. - `region_change`의 `location`은 처음 온 사람의 자동 위치 맞춤도 포함한다. - 설치는 카드 노출 → 누름 → 설치 완료 → 홈 화면 실행 순서로 본다. 아이폰은 설치 완료를 알 수 없어 `app_launch`로 대신 본다. diff --git a/frontend/src/b/Sheets.tsx b/frontend/src/b/Sheets.tsx index 47107d0..3e65b88 100644 --- a/frontend/src/b/Sheets.tsx +++ b/frontend/src/b/Sheets.tsx @@ -1061,7 +1061,8 @@ function LoginSheet({ onDone, onLoggedIn, why }: { onDone: () => void; onLoggedI return } setTokens(res.access_token, res.refresh_token ?? null) - track('login', { method: 'google' }) + if (res.is_new) track('sign_up', { method: 'google' }) + else track('login', { method: 'google' }) onLoggedIn() } const fail = () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.') @@ -1117,7 +1118,8 @@ function TossLoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn onSuccess: (res) => { if (!res.result?.success || !res.access_token) return setError('토스 로그인을 마치지 못했어요. 한 번 더 눌러 주세요.') setTokens(res.access_token, res.refresh_token ?? null) - track('login', { method: 'toss' }) + if (res.is_new) track('sign_up', { method: 'toss' }) + else track('login', { method: 'toss' }) onLoggedIn() }, onError: () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.'), diff --git a/frontend/src/lib/analytics.ts b/frontend/src/lib/analytics.ts index 83008fd..62ef308 100644 --- a/frontend/src/lib/analytics.ts +++ b/frontend/src/lib/analytics.ts @@ -8,7 +8,7 @@ type Events = { 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' } + 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' } diff --git a/shared/api/client/types.gen.ts b/shared/api/client/types.gen.ts index 8bdee19..3514884 100644 --- a/shared/api/client/types.gen.ts +++ b/shared/api/client/types.gen.ts @@ -2425,6 +2425,12 @@ export type ResAuth = { */ refresh_token?: string | null; me?: Me | null; + /** + * Is New + * + * 이번 요청으로 새로 가입한 계정이면 true (GA sign_up) + */ + is_new?: boolean | null; }; /** From 82ca286ea4f168c8badf6bd10804cf29522c7a1c Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 30 Oct 2026 12:00:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20GA=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=84=20=ED=95=9C=EA=B5=AD=EC=96=B4?= =?UTF-8?q?=EB=A1=9C=20=E2=80=94=20=EC=BD=94=EB=93=9C=20=ED=82=A4=EB=8A=94?= =?UTF-8?q?=20=EA=B7=B8=EB=8C=80=EB=A1=9C,=20analytics.ts=20GA=5FNAME=20?= =?UTF-8?q?=EC=9D=B4=20=EB=B0=94=EA=BF=94=20=EB=B3=B4=EB=83=84(=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=C2=B7=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85?= =?UTF-8?q?=C2=B7=EA=B3=B5=EC=9C=A0=20=ED=8F=AC=ED=95=A8),=20=EC=B2=AB?= =?UTF-8?q?=ED=99=94=EB=A9=B4=5F=EB=A9=88=EC=B6=A4=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/이벤트_추적.md | 82 ++++++++++++++++++----------------- frontend/index.html | 2 +- frontend/src/lib/analytics.ts | 45 ++++++++++++++++++- 3 files changed, 87 insertions(+), 42 deletions(-) diff --git a/docs/이벤트_추적.md b/docs/이벤트_추적.md index ebfe8b9..72a99b3 100644 --- a/docs/이벤트_추적.md +++ b/docs/이벤트_추적.md @@ -14,7 +14,9 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 - 왜 GTM이 아니라 GA4 직접인가: 이벤트를 코드(`analytics.ts`)에서 정하므로, GTM을 쓰면 이벤트마다 트리거·태그를 한 번 더 만들어야 한다. 광고 픽셀도, 마케터가 직접 손볼 일도 아직 없다. - 모든 이벤트에 `platform: 'web' | 'toss'`가 붙는다. `index.html`의 `gtag('config')`에서 빌드 모드(`%MODE%`)로 정한다. GA4에서 보려면 맞춤 측정기준(이벤트 범위, `platform`)을 한 번 등록한다. - 개발 서버(`npm run dev`)에서는 `track()`이 이벤트를 보내지 않는다. 단 `index.html`의 페이지 조회(`page_view`)는 개발 서버에서도 나가므로 GA4에서 `localhost`를 걸러 본다. -- 이벤트 이름은 영어 snake_case. GA4 추천 이벤트(`share`, `login`, `sign_up`, `select_content`)는 이름을 그대로 써야 GA4 기본 보고서에 잡힌다. +- GA 에 찍히는 이벤트 이름은 한국어(띄어쓰기 대신 `_`, 40자 이내). 코드에서는 영어 키로 부르고 `analytics.ts` `GA_NAME` 이 한국어로 바꿔 보낸다. 새 이벤트는 `Events` 와 `GA_NAME` 둘 다 넣는다. +- 로그인·회원가입·공유·글_열기도 한국어라 GA4 기본 보고서(추천 이벤트 집계)에는 안 잡힌다. 탐색 보고서에서 이벤트 이름으로 본다. +- 2026-10-30 전 데이터는 영어 이름(괄호 안 코드 키)으로 남아 있다. - 값은 사람이 읽을 수 있게 한글 그대로 둔다 (예: `gak_name: '야장각'`). - 개인정보(아이디, 닉네임 등)는 값에 넣지 않는다. - 페이지 이동은 코드로 보내지 않는다. GA4 향상된 측정의 "브라우저 기록 이벤트 기반 페이지 변경"이 잡는다(기본 켜짐). 모든 이벤트에 GA4가 `page_location`을 붙이므로 어느 탭에서 일어났는지는 따로 보내지 않는다. @@ -23,45 +25,45 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 | 이벤트 | 언제 | 값 | 코드 | |---|---|---|---| -| `view_gak` | 각 상세 시트가 열려 데이터가 뜸 (같은 각은 한 번만) | `index_id`, `gak_name`, `score`, `rank` | `Sheets.tsx` `GakSheet` | -| `select_content` | 글 시트가 열려 데이터가 뜸 (같은 글은 한 번만) | `content_type: 'article'`, `item_id`(글 번호), `category`(분류 이름) | `Sheets.tsx` `ArticleSheet` | -| `share` | 공유창으로 보내기 성공, 또는 이미지 내려받기 | `content_type: 'image'`, `item_id`(공유 제목), `method: 'share_sheet' \| 'download'`, `ratio`(이미지 비율) | `Sheets.tsx` `ShareSheet` `send` | -| `login` | 로그인 성공 (이미 있던 계정) | `method: 'id' \| 'google' \| 'toss'`(앱인토스) | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | -| `sign_up` | 가입 성공 (구글·토스로 처음 들어와 계정이 새로 생김, 서버 응답 `is_new`) | `method: 'id' \| 'google' \| 'toss'` | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | -| `region_change` | 지역 목록에서 고름, 또는 위치로 가까운 구를 찾음 | `region_name`, `method: 'list' \| 'location'` | `Sheets.tsx` `RegionSheet`, `region.tsx` `findNearest` | -| `install_banner_view` | 오늘 탭의 '홈 화면에 추가' 카드가 보임 (설치할 수 있는 곳에서, 닫은 지 2주 안 지났으면 안 보임) | 없음 | `installBanner.tsx` `InstallBanner` | -| `install_click` | '홈 화면에 추가'를 누름 | `from: 'banner' \| 'menu'`(카드·내 정보 메뉴), `method: 'prompt' \| 'guide'`(설치창을 띄움·기기별 안내를 염) | `install.ts` `useInstall` | -| `install_choice` | 설치창에서 고름 (안드로이드·PC Chrome·Edge) | `outcome: 'accepted' \| 'dismissed'` | `install.ts` `promptInstall` | -| `install_done` | 설치 완료 (브라우저가 `appinstalled`를 줄 때만. 아이폰은 오지 않음) | 없음 | `install.ts` | -| `app_launch` | 홈 화면 아이콘(설치한 앱)으로 엶 | `mode: 'standalone'` | `main.tsx` | -| `boot_stuck` | 8초 넘게 '날씨 불러오는 중' 첫 화면이 남음 (페이지마다 한 번) | `reason`(첫 오류 문구, 100자), `seconds`, `tries`(연달아 다시 불러온 횟수), `app_started`(앱 파일 실행 여부) | `index.html` 첫 화면 스크립트 | -| `sheet_open` | 아래에서 올라오는 창이 열림 (각·글·보내기·댓글·로그인·내 정보·지역·내 각·홈 화면 추가·점수 근거·이야기 등) | `sheet`(창 종류: `gak`·`article`·`share`·`comments`·`login`·`me`·`region`·`mix`·`myGak`·`install`·`weatherWhy`·`talk`·`seasonWeek`) | `Sheets.tsx` `SheetProvider` `open` | -| `like` | 좋아요 성공 (취소는 안 보냄) | `content_type: 'post' \| 'comment' \| 'talk' \| 'hero_post' \| 'gak_post' \| 'foliage_post' \| 'events_post' \| 'season_post'`, `item_id`(포스트·댓글·글 번호) | `Post.tsx` `FullCard`, `pinnedLike.ts`, `Sheets.tsx` `CommentRow`, `talk.tsx` | -| `comment` | 댓글 올리기 성공 | `post_id` | `Sheets.tsx` `CommentsSheet` `send` | -| `talk_comment` | 사람 글에 댓글 올리기 성공 (로그인한 사람만) | `talk_id`(글 번호) | `Sheets.tsx` `CommentsSheet` `send` | -| `terms_agree` | 댓글 쓰기 전 이용약관 동의 성공 | 없음 | `Sheets.tsx` `CommentsSheet` `agreeAndSend` | -| `report` | 신고 성공 | `content_type: 'comment' \| 'talk'`, `reason`(신고 이유 번호) | `Sheets.tsx` `CommentMenu`, `talk.tsx` | -| `block` | 차단 성공 | `content_type: 'comment' \| 'talk'` | `Sheets.tsx` `CommentMenu`, `talk.tsx` | -| `talk_post` | 이야기 글 올리기 성공 | `topic`(주제 번호, 6~9 는 기념일: 할로윈·빼빼로데이·크리스마스·추석), `with_image` | `talk.tsx` 글쓰기 `submit` | -| `feed_item_view` | 오늘 피드에 섞인 사람 글·행사 포스트가 처음 반쯤 보임 (한 장에 한 번) | `item_type: 'talk' \| 'event'`, `position`(피드에서 그 종류의 몇 번째) | `TodayPage.tsx` `Seen` | -| `hero_day_switch` | 히어로 오늘/내일 스위치를 바꿈 | `day: 'today' \| 'tomorrow'` | `TodayPage.tsx` | -| `tomorrow_to_today` | 내일 날씨 페이지(`/tomorrow/...`) 맨 아래 '오늘 ○○ 소식 보기'를 누름 | `region_name` | `TomorrowFeed.tsx` | -| `shorts_open` | 쇼츠 페이지(/shorts/영상ID)로 들어옴 (오늘 화면 쇼츠 줄·공유 링크) | `video_id` | `Shorts.tsx` `ShortsPage` | -| `shorts_view` | 쇼츠를 넘겨 다른 영상으로 감 | `video_id`, `index`(목록 순서) | `Shorts.tsx` `ShortsPage` | -| `shorts_sound` | 쇼츠 소리 켜기·끄기 | `on` | `Shorts.tsx` `toggleSound` | -| `foliage_open` | 단풍 지도 페이지(/foliage)를 엶 | 없음 | `FoliagePage.tsx` | -| `foliage_spot` | 단풍 명소를 고름 | `spot_name`, `from: 'page' \| 'card'`(지도 페이지·오늘 화면 카드) | `FoliagePage.tsx`, `foliageMap.tsx` | -| `my_gak_save` | 내 각 만들기 성공 (로그인 전엔 기기에 저장) | `gak_name` | `myGakState.ts` `create` | -| `toss_intro_start` | 토스판 첫 소개 화면에서 '시작하기' | 없음 | `tossIntro.tsx` | -| `install_banner_close` | '홈 화면에 추가' 띠를 × 로 닫음 | 없음 | `installBanner.tsx` | -| `fortune_draw` | 오늘 한 장에서 카드를 뽑음 (하루 한 번, 다시 열 때는 안 보냄) | `card`(각 코드) | `fortune.tsx` `useTodayCard` | -| `day_log` | 저녁 체크인을 적어 둠 (고쳐 적어도 보냄). 다녀온 곳 이름은 보내지 않음 | `mood`(1~5), `went_out`, `card_hit`(맞았어요 true·글쎄요 false·안 고름 null) | `fortune.tsx` `useTodayCard` | -| `today_icon` | 오늘 탭 아이콘 줄에서 아이콘을 누름 | `icon`(`tarot`·`saju`·`game`·`foliage`·`shorts`·`myGak`·`talk`) | `todayIcons.tsx` `TodayIcons` | -| `saju_input` | 날씨 사주 생년월일을 넣음 (생년월일 값은 보내지 않음) | `with_time` | `SajuPage.tsx` `BirthForm` | -| `saju_view` | 날씨 사주 결과가 뜸 | `scene`(내 기운 이름), `score`, `strength`(신강·중화·신약), `top_element`(가장 센 오행) | `SajuPage.tsx` `Reading` | -| `game_start` | 구름 합치기 한 판의 첫 그림을 떨어뜨림 (페이지만 열고 안 한 사람과 구분) | `again`(다시 하기로 시작), `logged_in`, `wind_ms`(오늘 우리 구 풍속), `theme`(그림: `basic`·`halloween`·`pepero`·`christmas`·`chuseok`, `holiday.ts`) | `CloudMergePage.tsx` `onUp` | -| `game_round` | 구름 합치기 라운드를 깸 | `round`(깬 라운드), `score`(그때 총점), `logged_in`(각을 받는지) | `CloudMergePage.tsx` `onScore` | -| `game_over` | 구름 합치기가 넘쳐서 끝남 | `round`(끝난 라운드), `score`, `best`(최고 기록 갱신), `drops`(떨어뜨린 횟수) | `CloudMergePage.tsx` `onOver` | +| `각_보기` (코드 `view_gak`) | 각 상세 시트가 열려 데이터가 뜸 (같은 각은 한 번만) | `index_id`, `gak_name`, `score`, `rank` | `Sheets.tsx` `GakSheet` | +| `글_열기` (코드 `select_content`) | 글 시트가 열려 데이터가 뜸 (같은 글은 한 번만) | `content_type: 'article'`, `item_id`(글 번호), `category`(분류 이름) | `Sheets.tsx` `ArticleSheet` | +| `공유` (코드 `share`) | 공유창으로 보내기 성공, 또는 이미지 내려받기 | `content_type: 'image'`, `item_id`(공유 제목), `method: 'share_sheet' \| 'download'`, `ratio`(이미지 비율) | `Sheets.tsx` `ShareSheet` `send` | +| `로그인` (코드 `login`) | 로그인 성공 (이미 있던 계정) | `method: 'id' \| 'google' \| 'toss'`(앱인토스) | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | +| `회원가입` (코드 `sign_up`) | 가입 성공 (구글·토스로 처음 들어와 계정이 새로 생김, 서버 응답 `is_new`) | `method: 'id' \| 'google' \| 'toss'` | `Sheets.tsx` `LoginSheet` `done`, `TossLoginSheet` | +| `지역_변경` (코드 `region_change`) | 지역 목록에서 고름, 또는 위치로 가까운 구를 찾음 | `region_name`, `method: 'list' \| 'location'` | `Sheets.tsx` `RegionSheet`, `region.tsx` `findNearest` | +| `설치배너_노출` (코드 `install_banner_view`) | 오늘 탭의 '홈 화면에 추가' 카드가 보임 (설치할 수 있는 곳에서, 닫은 지 2주 안 지났으면 안 보임) | 없음 | `installBanner.tsx` `InstallBanner` | +| `설치_누름` (코드 `install_click`) | '홈 화면에 추가'를 누름 | `from: 'banner' \| 'menu'`(카드·내 정보 메뉴), `method: 'prompt' \| 'guide'`(설치창을 띄움·기기별 안내를 염) | `install.ts` `useInstall` | +| `설치_선택` (코드 `install_choice`) | 설치창에서 고름 (안드로이드·PC Chrome·Edge) | `outcome: 'accepted' \| 'dismissed'` | `install.ts` `promptInstall` | +| `설치_완료` (코드 `install_done`) | 설치 완료 (브라우저가 `appinstalled`를 줄 때만. 아이폰은 오지 않음) | 없음 | `install.ts` | +| `앱_실행` (코드 `app_launch`) | 홈 화면 아이콘(설치한 앱)으로 엶 | `mode: 'standalone'` | `main.tsx` | +| `첫화면_멈춤` (코드 `boot_stuck`) | 8초 넘게 '날씨 불러오는 중' 첫 화면이 남음 (페이지마다 한 번) | `reason`(첫 오류 문구, 100자), `seconds`, `tries`(연달아 다시 불러온 횟수), `app_started`(앱 파일 실행 여부) | `index.html` 첫 화면 스크립트 | +| `창_열기` (코드 `sheet_open`) | 아래에서 올라오는 창이 열림 (각·글·보내기·댓글·로그인·내 정보·지역·내 각·홈 화면 추가·점수 근거·이야기 등) | `sheet`(창 종류: `gak`·`article`·`share`·`comments`·`login`·`me`·`region`·`mix`·`myGak`·`install`·`weatherWhy`·`talk`·`seasonWeek`) | `Sheets.tsx` `SheetProvider` `open` | +| `좋아요` (코드 `like`) | 좋아요 성공 (취소는 안 보냄) | `content_type: 'post' \| 'comment' \| 'talk' \| 'hero_post' \| 'gak_post' \| 'foliage_post' \| 'events_post' \| 'season_post'`, `item_id`(포스트·댓글·글 번호) | `Post.tsx` `FullCard`, `pinnedLike.ts`, `Sheets.tsx` `CommentRow`, `talk.tsx` | +| `댓글` (코드 `comment`) | 댓글 올리기 성공 | `post_id` | `Sheets.tsx` `CommentsSheet` `send` | +| `이야기_댓글` (코드 `talk_comment`) | 사람 글에 댓글 올리기 성공 (로그인한 사람만) | `talk_id`(글 번호) | `Sheets.tsx` `CommentsSheet` `send` | +| `약관_동의` (코드 `terms_agree`) | 댓글 쓰기 전 이용약관 동의 성공 | 없음 | `Sheets.tsx` `CommentsSheet` `agreeAndSend` | +| `신고` (코드 `report`) | 신고 성공 | `content_type: 'comment' \| 'talk'`, `reason`(신고 이유 번호) | `Sheets.tsx` `CommentMenu`, `talk.tsx` | +| `차단` (코드 `block`) | 차단 성공 | `content_type: 'comment' \| 'talk'` | `Sheets.tsx` `CommentMenu`, `talk.tsx` | +| `이야기_올림` (코드 `talk_post`) | 이야기 글 올리기 성공 | `topic`(주제 번호, 6~9 는 기념일: 할로윈·빼빼로데이·크리스마스·추석), `with_image` | `talk.tsx` 글쓰기 `submit` | +| `피드_항목_노출` (코드 `feed_item_view`) | 오늘 피드에 섞인 사람 글·행사 포스트가 처음 반쯤 보임 (한 장에 한 번) | `item_type: 'talk' \| 'event'`, `position`(피드에서 그 종류의 몇 번째) | `TodayPage.tsx` `Seen` | +| `오늘내일_전환` (코드 `hero_day_switch`) | 히어로 오늘/내일 스위치를 바꿈 | `day: 'today' \| 'tomorrow'` | `TodayPage.tsx` | +| `내일에서_오늘로` (코드 `tomorrow_to_today`) | 내일 날씨 페이지(`/tomorrow/...`) 맨 아래 '오늘 ○○ 소식 보기'를 누름 | `region_name` | `TomorrowFeed.tsx` | +| `쇼츠_열기` (코드 `shorts_open`) | 쇼츠 페이지(/shorts/영상ID)로 들어옴 (오늘 화면 쇼츠 줄·공유 링크) | `video_id` | `Shorts.tsx` `ShortsPage` | +| `쇼츠_보기` (코드 `shorts_view`) | 쇼츠를 넘겨 다른 영상으로 감 | `video_id`, `index`(목록 순서) | `Shorts.tsx` `ShortsPage` | +| `쇼츠_소리` (코드 `shorts_sound`) | 쇼츠 소리 켜기·끄기 | `on` | `Shorts.tsx` `toggleSound` | +| `단풍지도_열기` (코드 `foliage_open`) | 단풍 지도 페이지(/foliage)를 엶 | 없음 | `FoliagePage.tsx` | +| `단풍명소_보기` (코드 `foliage_spot`) | 단풍 명소를 고름 | `spot_name`, `from: 'page' \| 'card'`(지도 페이지·오늘 화면 카드) | `FoliagePage.tsx`, `foliageMap.tsx` | +| `내각_저장` (코드 `my_gak_save`) | 내 각 만들기 성공 (로그인 전엔 기기에 저장) | `gak_name` | `myGakState.ts` `create` | +| `토스소개_시작` (코드 `toss_intro_start`) | 토스판 첫 소개 화면에서 '시작하기' | 없음 | `tossIntro.tsx` | +| `설치배너_닫기` (코드 `install_banner_close`) | '홈 화면에 추가' 띠를 × 로 닫음 | 없음 | `installBanner.tsx` | +| `타로_뽑기` (코드 `fortune_draw`) | 오늘 한 장에서 카드를 뽑음 (하루 한 번, 다시 열 때는 안 보냄) | `card`(각 코드) | `fortune.tsx` `useTodayCard` | +| `하루_기록` (코드 `day_log`) | 저녁 체크인을 적어 둠 (고쳐 적어도 보냄). 다녀온 곳 이름은 보내지 않음 | `mood`(1~5), `went_out`, `card_hit`(맞았어요 true·글쎄요 false·안 고름 null) | `fortune.tsx` `useTodayCard` | +| `오늘아이콘_누름` (코드 `today_icon`) | 오늘 탭 아이콘 줄에서 아이콘을 누름 | `icon`(`tarot`·`saju`·`game`·`foliage`·`shorts`·`myGak`·`talk`) | `todayIcons.tsx` `TodayIcons` | +| `사주_입력` (코드 `saju_input`) | 날씨 사주 생년월일을 넣음 (생년월일 값은 보내지 않음) | `with_time` | `SajuPage.tsx` `BirthForm` | +| `사주_결과` (코드 `saju_view`) | 날씨 사주 결과가 뜸 | `scene`(내 기운 이름), `score`, `strength`(신강·중화·신약), `top_element`(가장 센 오행) | `SajuPage.tsx` `Reading` | +| `게임_시작` (코드 `game_start`) | 구름 합치기 한 판의 첫 그림을 떨어뜨림 (페이지만 열고 안 한 사람과 구분) | `again`(다시 하기로 시작), `logged_in`, `wind_ms`(오늘 우리 구 풍속), `theme`(그림: `basic`·`halloween`·`pepero`·`christmas`·`chuseok`, `holiday.ts`) | `CloudMergePage.tsx` `onUp` | +| `게임_라운드` (코드 `game_round`) | 구름 합치기 라운드를 깸 | `round`(깬 라운드), `score`(그때 총점), `logged_in`(각을 받는지) | `CloudMergePage.tsx` `onScore` | +| `게임_끝` (코드 `game_over`) | 구름 합치기가 넘쳐서 끝남 | `round`(끝난 라운드), `score`, `best`(최고 기록 갱신), `drops`(떨어뜨린 횟수) | `CloudMergePage.tsx` `onOver` | - 공유창에서 사용자가 취소하면 `share`를 보내지 않는다. - 구름 합치기 게임 방법 창은 `sheet_open`(`sheet: 'gameHelp'`)으로 잡혀 따로 보내지 않는다. diff --git a/frontend/index.html b/frontend/index.html index a7c69a8..c7241b6 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -86,7 +86,7 @@ } boot.appendChild(p) boot.appendChild(b) - gtag('event', 'boot_stuck', { reason: reason.slice(0, 100), seconds: Math.round((Date.now() - start) / 1000), tries: tries(), app_started: !!window.__appStarted }) + gtag('event', '첫화면_멈춤', { reason: reason.slice(0, 100), seconds: Math.round((Date.now() - start) / 1000), tries: tries(), app_started: !!window.__appStarted }) }, 8000) var timer = setInterval(function () { if (document.getElementById('boot')) retry() diff --git a/frontend/src/lib/analytics.ts b/frontend/src/lib/analytics.ts index 62ef308..e1ad0c7 100644 --- a/frontend/src/lib/analytics.ts +++ b/frontend/src/lib/analytics.ts @@ -54,7 +54,50 @@ 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: '내일에서_오늘로', + 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', event, params) + window.gtag?.('event', GA_NAME[event], params) }