func recordGameOver() { let tracker = GAI.sharedInstance().defaultTracker let gameOverEvent = GAIDictionaryBuilder.createEvent(withCategory: "gameOver", action: "totalScore", label: "", value: myGameStats.totalScore as NSNumber) let enemiesBeatenEvent = GAIDictionaryBuilder.createEvent(withCategory: "gameOver", action: "enemiesBeaten", label: "", value: myGameStats.enemiesBeaten as NSNumber) let roundsSurvivedEvent = GAIDictionaryBuilder.createEvent(withCategory: "gameOver", action: "roundsSurvived", label: "", value: myGameStats.roundsSurvived as NSNumber) tracker?.send(gameOverEvent.build() as [NSObject: AnyObject]) tracker?.send(enemiesBeatenEvent.build() as [NSObject: AnyObject]) tracker?.send(roundsSurvivedEvent.build() as [NSObject: AnyObject]) }
FIRAnalytics.logEvent(withName: "gameOverTotalScore", parameters: [kFIRParameterValue: myGameStats.totalScore as NSObject]) FIRAnalytics.logEvent(withName: "gameOverEnemiesBeaten", parameters: [kFIRParameterValue: myGameStats.totalScore as NSObject]) FIRAnalytics.logEvent(withName: "gameOverTotalScore", parameters: [kFIRParameterValue: myGameStats.totalScore as NSObject])
let finalStats = ["totalScore": myGameStats.totalScore as NSObject, "enemiesBeaten": myGameStats.enemiesBeaten as NSObject, "roundsSurvived": myGameStats.roundsSurvived as NSObject] FIRAnalytics.logEvent(withName: "gameOver", parameters: finalStats)
GoogleService-info.plist
GoogleService-info
TRACKING_ID
func recordGameOver() { // All the old code you had previously to record Google Analytics // … // … So much code … // … // Now add the Firebase stuff let finalStats = ["totalScore": myGameStats.totalScore as NSObject, "enemiesBeaten": myGameStats.enemiesBeaten as NSObject, "roundsSurvived": myGameStats.roundsSurvived as NSObject] FIRAnalytics.logEvent(withName: "gameOver", parameters: finalStats) }
func recordGameOver() { let finalStats = ["totalScore": myGameStats.totalScore as NSObject, "enemiesBeaten": myGameStats.enemiesBeaten as NSObject, "roundsSurvived": myGameStats.roundsSurvived as NSObject] FIRAnalytics.logEvent(withName: "gameOver", parameters: finalStats) // That's it! }
SELECT AVG(hit.eventInfo.eventValue) FROM `my_awesome_app.ga_sessions_20170123`, UNNEST(hits) AS hit WHERE hit.eventInfo.eventCategory = "gameOver" AND hit.eventInfo.eventAction = "totalScore"
SELECT COUNT(*), AVG(total_score) AS average FROM ( SELECT event_param.value.int_value AS total_score FROM `firebase-project.com_example_awesome_app.app_events_20170123`, UNNEST(event_dim) AS event, UNNEST(event.params) AS event_param WHERE event.name = "gameOver" AND event_param.key = "totalScore" UNION ALL SELECT hit.eventInfo.eventValue AS total_score FROM `my_awesome_app.ga_sessions_20170123`, UNNEST(hits) AS hit WHERE hit.eventInfo.eventCategory = "gameOver" AND hit.eventInfo.eventAction = "totalScore" )