///---------------------------------------------- /// Flurry Analytics Plugin /// Copyright © 2016 Aleksei Kuzin ///---------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using System; namespace KHD { public class FlurryAnalyticsTest : MonoBehaviour { public bool startSessionFromCode = true; public static FlurryAnalyticsTest Instance; void Awake() { if (Instance != null && Instance != this) { Debug.LogWarning("FlurryLogger instance already exists on another gameObject. Destroying this gameObject FlurryLogger"); Destroy(gameObject); return; } Instance = this; DontDestroyOnLoad(gameObject); } private void Start() { if (!startSessionFromCode) { return; } KHD.FlurryAnalytics.Instance.SetDebugLogEnabled(true); // Enable data replication to UnityAnalytics. // KHD.FlurryAnalytics.Instance.replicateDataToUnityAnalytics = true; // Set custom app version. // KHD.FlurryAnalytics.Instance.SetAppVersion("1.0.0"); // Track unique user info. // KHD.FlurryAnalytics.Instance.SetUserId("ioufewjkhjwdfsmnfbweoiufj"/* replace with user unique id */); // KHD.FlurryAnalytics.Instance.SetGender(KHD.FlurryAnalytics.Gender.Male); // KHD.FlurryAnalytics.Instance.SetAge(32); // Enables implicit recording of Apple Store transactions. #if UNITY_IOS //KHD.FlurryAnalyticsIOS.SetIAPReportingEnabled(true); #endif // Just one line of code to get wide range of metrics like: // Sessions // Active Users // New Users // Session Length // Frequency of Use // Custom User Segments // User Retention // Version Adoption // Devices // Carriers // Firmware Versions KHD.FlurryAnalytics.Instance.StartSession( "782HFPDK6J57DNZJYS9G", // - replace with your API KEY. "JCFXFP8WQQRB2Y39JQZR", // - replace with your API KEY. true); } public void GameFinishLevel1(int point) { LogFlurryEvent("Game Finish Level 1", "point", point.ToString()); } public void GameFinishLevel2(int point) { LogFlurryEvent("Game Finish Level 2", "point", point.ToString()); } public void GameFinishLevel3(int point) { LogFlurryEvent("Game Finish Level 3", "point", point.ToString()); } // private void OnGUI() { // var index = 0; // if (Button("Log Event", index++)) { // KHD.FlurryAnalytics.Instance.LogEvent("KHD Sample Event"); // } // if (Button("Log Event Wit Parameters", index++)) { // KHD.FlurryAnalytics.Instance.LogEventWithParameters( // "KHD Sample Event with parameters", // new Dictionary() { // { "Param1", "Value1" }, // { "Param2", "Value2" }, // { "Param3", "Value3" }, // }); // } // if (Button("Log Timed Event", index++)) { // KHD.FlurryAnalytics.Instance.LogEvent("KHD Sample Timed Event New", true); // } // if (Button("End Timed Event", index++)) { // KHD.FlurryAnalytics.Instance.EndTimedEvent("KHD Sample Timed Event New"); // } //#if UNITY_ANDROID // if (Button("Log Payment", index++)) { // var random = new System.Random(); // KHD.FlurryAnalyticsAndroid.LogPayment( // "Test Payment", "com.khd.testpayment", 1, // 0.99, "USD", // // You should use appropriate transactionId. Only for test. // SystemInfo.deviceUniqueIdentifier + random.Next(), // null // ); // } //#endif // } void OnDestroy() { #if UNITY_IPHONE #endif #if UNITY_ANDROID //FlurryAgent.Instance.onEndSession(); #endif } public void GamePlayed() { LogFlurryEvent("Games played"); } public void RescueMoment() { LogFlurryEvent("Rescue moment"); } public void InviteFriends() { LogFlurryEvent("Invite friends"); } public void GameFinish(int dist, int packs, int score) { //LogFlurryEvent("GamesFinish", "meters", dist.ToString(), "packages", packs.ToString(), "score", score.ToString()); LogFlurryEvent("Meters run", "meters", dist.ToString()); LogFlurryEvent("Packages collected", "packages", packs.ToString()); LogFlurryEvent("Score achieved", "score", score.ToString()); } public void CouponWon() { LogFlurryEvent("Coupon won"); } public void CouponConsumed() { LogFlurryEvent("Coupon consumed"); } public void EndGame() { LogFlurryEvent("End Game", "id", SystemInfo.deviceUniqueIdentifier); } public void ShowVideoAd() { LogFlurryEvent("Show video ad", "id", SystemInfo.deviceUniqueIdentifier); } public void ShowFullScreenAd() { LogFlurryEvent("Show fullscreen ad", "id", SystemInfo.deviceUniqueIdentifier); } public void CapCode() { LogFlurryEvent("Cap code"); } public void LogFlurryEvent(string eventName) { Debug.Log(string.Format("Sending a Flurry event '{0}'", eventName)); #if UNITY_EDITOR // return; #endif var parameters = new Dictionary(); parameters.Add("event data", "empty"); KHD.FlurryAnalytics.Instance.LogEventWithParameters(eventName, parameters); } public void LogFlurryEvent(string eventName, params string[] keyValues) { //Debug.Assert (keyValues.Length % 2 == 0, "Make sure to pass key value pairs"); Debug.Log(string.Format("Sending a Flurry event '{0}' with the following parameters '{1}'", eventName, string.Join(", ", keyValues))); #if UNITY_EDITOR // return; #endif var parameters = new Dictionary(); for (int i = 0; i < keyValues.Length; i += 2) { parameters[keyValues[i]] = keyValues[i + 1]; } KHD.FlurryAnalytics.Instance.LogEventWithParameters(eventName, parameters); } public void SendPhone() { LogFlurryEvent("Send phone"); } public void GameStartLevel1() { LogFlurryEvent("Game Start Level 1"); } public void GameStartLevel2() { LogFlurryEvent("Game Start Level 2"); } public void GameStartLevel3() { LogFlurryEvent("Game Start Level 3"); } //private bool Button(string label, int index) { // var width = Screen.width * 0.8f; // var height = Screen.height * 0.07f; // var rect = new Rect((Screen.width - width) * 0.5f, // index * height + height * 0.5f, // width, height); // return GUI.Button(rect, label); //} } }