FlurryAnalyticsTest.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ///----------------------------------------------
  2. /// Flurry Analytics Plugin
  3. /// Copyright © 2016 Aleksei Kuzin
  4. ///----------------------------------------------
  5. using UnityEngine;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. namespace KHD {
  9. public class FlurryAnalyticsTest : MonoBehaviour {
  10. public bool startSessionFromCode = true;
  11. public static FlurryAnalyticsTest Instance;
  12. void Awake()
  13. {
  14. if (Instance != null && Instance != this)
  15. {
  16. Debug.LogWarning("FlurryLogger instance already exists on another gameObject. Destroying this gameObject FlurryLogger");
  17. Destroy(gameObject);
  18. return;
  19. }
  20. Instance = this;
  21. DontDestroyOnLoad(gameObject);
  22. }
  23. private void Start() {
  24. if (!startSessionFromCode) {
  25. return;
  26. }
  27. KHD.FlurryAnalytics.Instance.SetDebugLogEnabled(true);
  28. // Enable data replication to UnityAnalytics.
  29. // KHD.FlurryAnalytics.Instance.replicateDataToUnityAnalytics = true;
  30. // Set custom app version.
  31. // KHD.FlurryAnalytics.Instance.SetAppVersion("1.0.0");
  32. // Track unique user info.
  33. // KHD.FlurryAnalytics.Instance.SetUserId("ioufewjkhjwdfsmnfbweoiufj"/* replace with user unique id */);
  34. // KHD.FlurryAnalytics.Instance.SetGender(KHD.FlurryAnalytics.Gender.Male);
  35. // KHD.FlurryAnalytics.Instance.SetAge(32);
  36. // Enables implicit recording of Apple Store transactions.
  37. #if UNITY_IOS
  38. //KHD.FlurryAnalyticsIOS.SetIAPReportingEnabled(true);
  39. #endif
  40. // Just one line of code to get wide range of metrics like:
  41. // Sessions
  42. // Active Users
  43. // New Users
  44. // Session Length
  45. // Frequency of Use
  46. // Custom User Segments
  47. // User Retention
  48. // Version Adoption
  49. // Devices
  50. // Carriers
  51. // Firmware Versions
  52. KHD.FlurryAnalytics.Instance.StartSession(
  53. "YZDTTDG7HYYH49XWKGXX", // - replace with your API KEY.
  54. "HJN25CPKX76WRZ3ZMQDH", // - replace with your API KEY.
  55. true);
  56. }
  57. // private void OnGUI() {
  58. // var index = 0;
  59. // if (Button("Log Event", index++)) {
  60. // KHD.FlurryAnalytics.Instance.LogEvent("KHD Sample Event");
  61. // }
  62. // if (Button("Log Event Wit Parameters", index++)) {
  63. // KHD.FlurryAnalytics.Instance.LogEventWithParameters(
  64. // "KHD Sample Event with parameters",
  65. // new Dictionary<string, string>() {
  66. // { "Param1", "Value1" },
  67. // { "Param2", "Value2" },
  68. // { "Param3", "Value3" },
  69. // });
  70. // }
  71. // if (Button("Log Timed Event", index++)) {
  72. // KHD.FlurryAnalytics.Instance.LogEvent("KHD Sample Timed Event New", true);
  73. // }
  74. // if (Button("End Timed Event", index++)) {
  75. // KHD.FlurryAnalytics.Instance.EndTimedEvent("KHD Sample Timed Event New");
  76. // }
  77. //#if UNITY_ANDROID
  78. // if (Button("Log Payment", index++)) {
  79. // var random = new System.Random();
  80. // KHD.FlurryAnalyticsAndroid.LogPayment(
  81. // "Test Payment", "com.khd.testpayment", 1,
  82. // 0.99, "USD",
  83. // // You should use appropriate transactionId. Only for test.
  84. // SystemInfo.deviceUniqueIdentifier + random.Next(),
  85. // null
  86. // );
  87. // }
  88. //#endif
  89. // }
  90. void OnDestroy()
  91. {
  92. #if UNITY_IPHONE
  93. #endif
  94. #if UNITY_ANDROID
  95. //FlurryAgent.Instance.onEndSession();
  96. #endif
  97. }
  98. public void GamePlayed()
  99. {
  100. LogFlurryEvent("Games played");
  101. }
  102. public void RescueMoment()
  103. {
  104. LogFlurryEvent("Rescue moment");
  105. }
  106. public void InviteFriends()
  107. {
  108. LogFlurryEvent("Invite friends");
  109. }
  110. public void GameFinish(int dist, int packs, int score)
  111. {
  112. //LogFlurryEvent("GamesFinish", "meters", dist.ToString(), "packages", packs.ToString(), "score", score.ToString());
  113. LogFlurryEvent("Meters run", "meters", dist.ToString());
  114. LogFlurryEvent("Packages collected", "packages", packs.ToString());
  115. LogFlurryEvent("Score achieved", "score", score.ToString());
  116. }
  117. public void CouponWon()
  118. {
  119. LogFlurryEvent("Coupon won");
  120. }
  121. public void CouponConsumed()
  122. {
  123. LogFlurryEvent("Coupon consumed");
  124. }
  125. public void EndGame()
  126. {
  127. LogFlurryEvent("End Game", "id", SystemInfo.deviceUniqueIdentifier);
  128. }
  129. public void ShowVideoAd()
  130. {
  131. LogFlurryEvent("Show video ad", "id", SystemInfo.deviceUniqueIdentifier);
  132. }
  133. public void ShowFullScreenAd()
  134. {
  135. LogFlurryEvent("Show fullscreen ad", "id", SystemInfo.deviceUniqueIdentifier);
  136. }
  137. public void CapCode()
  138. {
  139. LogFlurryEvent("Cap code");
  140. }
  141. public void LogFlurryEvent(string eventName)
  142. {
  143. Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}'</color>", eventName));
  144. #if UNITY_EDITOR
  145. // return;
  146. #endif
  147. var parameters = new Dictionary<string, string>();
  148. parameters.Add("event data", "empty");
  149. KHD.FlurryAnalytics.Instance.LogEventWithParameters(eventName, parameters);
  150. }
  151. public void LogFlurryEvent(string eventName, params string[] keyValues)
  152. {
  153. //Debug.Assert (keyValues.Length % 2 == 0, "Make sure to pass key value pairs");
  154. Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}' with the following parameters '{1}'</color>", eventName, string.Join(", ", keyValues)));
  155. #if UNITY_EDITOR
  156. // return;
  157. #endif
  158. var parameters = new Dictionary<string, string>();
  159. for (int i = 0; i < keyValues.Length; i += 2)
  160. {
  161. parameters[keyValues[i]] = keyValues[i + 1];
  162. }
  163. KHD.FlurryAnalytics.Instance.LogEventWithParameters(eventName, parameters);
  164. }
  165. //private bool Button(string label, int index) {
  166. // var width = Screen.width * 0.8f;
  167. // var height = Screen.height * 0.07f;
  168. // var rect = new Rect((Screen.width - width) * 0.5f,
  169. // index * height + height * 0.5f,
  170. // width, height);
  171. // return GUI.Button(rect, label);
  172. //}
  173. }
  174. }