feat: 구름 합치기 GA4 이벤트 — game_start(첫 그림)·game_round(라운드 깸)·game_over(넘침)

This commit is contained in:
minaChoi committed 2026-10-29 09:06:46 +09:00
1 parent 7aad7f929c
commit 2f4a0c3bad
3 files changed
+17

No files matched your search

+10
View File
@@ -7,6 +7,7 @@ import { gameRound, gameStart } from '@nalssigak/shared/api/client/sdk.gen'
import type { ResLevel } from '@nalssigak/shared/api/client/types.gen'
import { kst } from '@nalssigak/shared/lib'
import { slotAt } from '@nalssigak/shared/lib/weatherText'
import { track } from '../lib/analytics'
import { cx } from '../lib/utils'
import { useAuth } from './authContext'
import { createGame, DROP_Y, H, LEVELS, LINE_Y, loadBest, randomLevel, roundTarget, saveBest, W, windDir, type Game } from './cloudMerge'
@@ -106,6 +107,8 @@ export function CloudMergePage() {
const [next, setNext] = useState(randomLevel)
const nextRef = useRef(next)
const coolRef = useRef(0)
// 이번 판에 떨어뜨린 횟수: 0 이면 아직 시작 전(첫 그림에서 game_start)
const dropsRef = useRef(0)
const [score, setScore] = useState(0)
const [best, setBest] = useState(loadBest)
const [over, setOver] = useState(false)
@@ -124,6 +127,8 @@ export function CloudMergePage() {
canvas.height = H * ratio
ctx.scale(ratio, ratio)
let roundNo = 1
let total = 0
dropsRef.current = 0
let base = 0
let flashTimer: ReturnType<typeof setTimeout> | undefined
let ticket: Promise<string | undefined> = Promise.resolve(undefined)
@@ -154,6 +159,7 @@ export function CloudMergePage() {
}
const game = createGame(windMs, dir, {
onScore: (s) => {
total = s
setScore(s)
if (s - base >= roundTarget(roundNo)) {
roundNo += 1
@@ -164,6 +170,7 @@ export function CloudMergePage() {
clearTimeout(flashTimer)
flashTimer = setTimeout(() => setFlash(false), 1400)
void claim(roundNo - 1)
track('game_round', { round: roundNo - 1, score: s, logged_in: loggedIn })
}
setRoundGot(s - base)
if (s > loadBest()) {
@@ -173,6 +180,7 @@ export function CloudMergePage() {
},
onOver: () => {
setOver(true)
track('game_over', { round: roundNo, score: total, best: total > 0 && total >= loadBest(), drops: dropsRef.current })
settle()
},
})
@@ -205,6 +213,8 @@ export function CloudMergePage() {
const onUp = (e: PointerEvent<HTMLCanvasElement>) => {
const game = gameRef.current
if (!game || over || performance.now() < coolRef.current) return
if (dropsRef.current === 0) track('game_start', { again: play > 0, logged_in: loggedIn, wind_ms: windMs })
dropsRef.current += 1
game.drop(nextRef.current, toX(e))
coolRef.current = performance.now() + 450
nextRef.current = randomLevel()