123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- ///----------------------------------------------
- /// Flurry Analytics Plugin
- /// Copyright © 2016 Aleksei Kuzin
- ///----------------------------------------------
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- 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(
- "YZDTTDG7HYYH49XWKGXX", // - replace with your API KEY.
- "HJN25CPKX76WRZ3ZMQDH", // - replace with your API KEY.
- true);
- }
- // 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<string, string>() {
- // { "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("<color=yellow>Sending a Flurry event '{0}'</color>", eventName));
- #if UNITY_EDITOR
- // return;
- #endif
- var parameters = new Dictionary<string, string>();
- 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("<color=yellow>Sending a Flurry event '{0}' with the following parameters '{1}'</color>", eventName, string.Join(", ", keyValues)));
- #if UNITY_EDITOR
- // return;
- #endif
- var parameters = new Dictionary<string, string>();
- for (int i = 0; i < keyValues.Length; i += 2)
- {
- parameters[keyValues[i]] = keyValues[i + 1];
- }
- KHD.FlurryAnalytics.Instance.LogEventWithParameters(eventName, parameters);
- }
- //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);
- //}
- }
- }
|