void SendDeathEvent() { try { // Sending Kii Analytics event for game over stats KiiEvent ev = KiiAnalytics.NewEvent("PlayerDeath"); // Set key-value pairs ev ["time"] = Time.time; ev ["level"] = 1; // Upload Event Data to Kii Cloud KiiAnalytics.Upload((Exception e) => { if (e == null) { Debug.Log("Analytics event upload successful"); } else { Debug.Log("Analytics event upload error: " + e.ToString()); } }, ev); } catch (CloudException e) { Debug.Log("Analytics event upload error: " + e.ToString()); } }
public void Test_Non_Initialize_AnalyticsAPI_Async() { try { KiiEvent ev = KiiAnalytics.NewEvent("MyUser"); KiiAnalytics.Upload((Exception e) => { }, ev); Assert.Fail("InvalidOperationException isn't thrown"); } catch (InvalidOperationException e) { Assert.AreEqual(ErrorInfo.UTILS_KIICLIENT_NULL, e.Message); } try { ResultCondition condition = new ResultCondition(); KiiAnalytics.GetResult("1234", condition, (string ruleId, ResultCondition c, GroupedResult r, Exception e) => { }); Assert.Fail("InvalidOperationException isn't thrown"); } catch (InvalidOperationException e) { Assert.AreEqual(ErrorInfo.UTILS_KIICLIENT_NULL, e.Message); } }
void CalculateScore() { #if !UNITY_FLASH recordedTime = (int)GameScore.GameTime; #endif deaths = GameScore.Deaths; buzzerKills = GameScore.GetKills("KamikazeBuzzer"); spiderKills = GameScore.GetKills("EnemySpider"); mechKills = GameScore.GetKills("EnemyMech") + GameScore.GetKills("ConfusedEnemyMech"); points = (int)(buzzerKills * kBuzzerKillPrize + spiderKills * kSpiderKillPrize + mechKills * kMechKillPrize); if (deaths != 0) { points /= (int)(deaths * kDeathCostFactor); } // Sending Kii Analytics event for game over stats Debug.Log("Sending game over event..."); KiiEvent ev = KiiAnalytics.NewEvent("GameOver"); // Set key-value pairs #if !UNITY_FLASH ev["recordedTime"] = recordedTime; #endif ev["deaths"] = deaths; ev["buzzerKills"] = buzzerKills; ev["spiderKills"] = spiderKills; ev["mechKills"] = mechKills; ev["points"] = points; // Upload Event Data to Kii Cloud KiiAnalytics.Upload((Exception e) => { if (e == null) { Debug.Log("GameOverGU: Analytics game over event upload successful"); } else { Debug.Log("GameOverGUI: Unable to upload game over event to Kii Cloud: " + e.ToString()); } }, ev); }
// Send Analytics event for end of level time public static void EndOfLevel(float gameTime) { Debug.Log("Sending end of level event..."); KiiEvent ev = KiiAnalytics.NewEvent("EndOfLevel"); // Set key-value pairs ev ["user"] = user.Username; ev ["time"] = gameTime; // Upload Event Data to Kii Cloud KiiAnalytics.Upload((Exception e) => { if (e == null) { Debug.Log("GameScore: Analytics end-of-level event upload successful"); } else { Debug.Log("GameScore: Unable to upload end-of-level event to Kii Cloud: " + e.ToString()); } }, ev); }
void OnGUI() { if (!this.loggedin) { this.email = GUI.TextField(new Rect(10, 10, 800, 100), this.email); GUI.Label(new Rect(10, 220, 500, 1000), this.message); if (GUI.Button(new Rect(10, 115, 250, 100), "Create User")) { try { KiiUser user = KiiUser.BuilderWithEmail(this.email).WithName("U" + Environment.TickCount).Build(); user.Register("pa$$sword"); this.message = "SUCCESS"; this.loggedin = true; this.message = ""; } catch (KiiCorp.Cloud.Storage.NetworkException e) { this.message = "ERROR: " + e.GetType() + "\n" + "Status=" + e.Status + "\n" + "Data=" + e.Data.ToString() + "\n" + "InnerExcepton=" + e.InnerException.GetType() + "\n" + "InnerExcepton.Message=" + e.InnerException.Message + "\n" + "InnerExcepton.Stacktrace=" + e.InnerException.StackTrace + "\n" + "Source=" + e.Source + "\n" + e.Message + "\n" + e.StackTrace; } catch (Exception e) { this.message = "ERROR: " + e.GetType() + " " + e.Message + "\n" + e.StackTrace; } } } else { GUI.Label(new Rect(10, 220, 500, 1000), message); try { if (this.experiment == null) { this.experiment = KiiExperiment.GetByID("8a835c5b-3508-41a9-9a7e-a348c513a426"); this.appliedVariation = experiment.GetAppliedVariation(experiment.Variations[0]); ConversionEvent viewCnvEvent = this.experiment.GetConversionEventByName("viewed"); KiiEvent viewKiiEvent = this.appliedVariation.EventForConversion(viewCnvEvent); KiiAnalytics.Upload(viewKiiEvent); } if (this.buttonCaption == null) { JsonObject json = this.appliedVariation.VariableSet; this.buttonCaption = json.GetString("caption"); } if (GUI.Button(new Rect(10, 10, 250, 100), this.buttonCaption)) { ConversionEvent cnvEvent = experiment.GetConversionEventByName("clicked"); KiiEvent kiiEvent = this.appliedVariation.EventForConversion(cnvEvent); KiiAnalytics.Upload(kiiEvent); Application.Quit(); } if (GUI.Button(new Rect(265, 10, 250, 100), "Cancel")) { Application.Quit(); } } catch (Exception e) { this.message = "ERROR: " + e.GetType() + " " + e.Message + "\n" + e.StackTrace; } } }
void OnGUI() { if (!this.loggedin) { this.email = GUI.TextField(new Rect(10, 10, 800, 100), this.email); GUI.Label(new Rect(10, 220, 500, 1000), this.message); if (GUI.Button(new Rect(10, 115, 250, 100), "Create User")) { KiiUser user = KiiUser.BuilderWithEmail(this.email).WithName("U" + Environment.TickCount).Build(); user.Register("pa$$sword", (KiiUser registeredUser, Exception e) => { if (e != null) { this.message = "ERROR: failed to register user " + e.GetType() + " " + e.Message + "\n" + e.StackTrace; } else { this.message = "SUCCESS"; this.loggedin = true; this.message = ""; } }); } } else { GUI.Label(new Rect(10, 220, 500, 1000), message); if (!this.initializedExperiment) { this.initializedExperiment = true; Debug.Log("#####Call KiiExperiment.GetByID"); KiiExperiment.GetByID("f1b00500-eae2-11e3-a0e4-22000a84b8f5", (KiiExperiment experiment, Exception e) => { Debug.Log("#####End KiiExperiment.GetByID"); if (e != null) { Debug.Log("#####Error KiiExperiment.GetByID"); this.message = "ERROR: KiiExperiment.GetByID failed!! " + e.GetType() + " " + e.Message + "\n" + e.StackTrace; return; } Debug.Log("#####Success KiiExperiment.GetByID"); this.experiment = experiment; this.appliedVariation = this.experiment.GetAppliedVariation(this.experiment.Variations[0]); ConversionEvent viewCnvEvent = this.experiment.GetConversionEventByName("viewed"); KiiEvent viewKiiEvent = this.appliedVariation.EventForConversion(viewCnvEvent); KiiAnalytics.Upload((Exception e1) => { if (e1 != null) { this.message = "ERROR: KiiAnalytics.Upload('viewed') failed!! " + e1.GetType() + " " + e1.Message + "\n" + e1.StackTrace; } else { this.message = "Event 'viewed' is Uploaded!!"; } } , viewKiiEvent); if (this.buttonCaption == null) { JsonObject json = this.appliedVariation.VariableSet; this.buttonCaption = json.GetString("caption"); } }); } if (GUI.Button(new Rect(10, 10, 250, 100), this.buttonCaption)) { ConversionEvent cnvEvent = this.experiment.GetConversionEventByName("clicked"); KiiEvent kiiEvent = this.appliedVariation.EventForConversion(cnvEvent); KiiAnalytics.Upload((Exception e2) => { if (e2 != null) { this.message = "ERROR: KiiAnalytics.Upload(clicked) failed!! " + e2.GetType() + " " + e2.Message + "\n" + e2.StackTrace; } else { this.message = "Event 'clicked' is Uploaded!!"; } }, kiiEvent); } if (GUI.Button(new Rect(265, 10, 250, 100), "Cancel")) { Application.Quit(); } } }