歡迎來到第二十八天!遊戲上線後,我們需要透過數據追蹤轉換率並監控系統異常。
// AnalyticsManager.ts
import posthog from 'posthog-js';
export class AnalyticsManager {
public static init() {
posthog.init('YOUR_POSTHOG_API_KEY', {
api_host: 'https://app.posthog.com',
autocapture: false // 手動控制精準埋點
});
}
public static trackGameStart(gameType: 'douhua' | 'shaved_ice') {
posthog.capture('game_start', { game_type: gameType });
}
public static trackStoreRedeem(itemId: String, costPoints: number) {
posthog.capture('store_redeem', { item_id: itemId, points: costPoints });
}
}
// Monitoring.kt
fun Application.configureMonitoring() {
Sentry.init { options ->
options.dsn = "https://your_sentry_dsn@sentry.io/12345"
options.tracesSampleRate = 0.2
}
install(StatusPages) {
exception<Throwable> { call, cause ->
Sentry.captureException(cause) // 自動回傳錯誤堆疊至 Sentry
call.respond(HttpStatusCode.InternalServerError, "系統繁忙中,請稍後再試")
}
}
}
Tech Tip:GA4 適合看高層級流量與管道來源;PostHog 適合看玩家在遊戲內動作的漏斗轉化率(Funnel Analysis);而 Sentry 則是程式除錯神器,能精準捕捉線上 JavaScript 或 Kotlin 崩潰事件與行號!