FlurryLogger.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class FlurryLogger : MonoBehaviour {
  5. private static FlurryLogger instance;
  6. public static FlurryLogger Instance
  7. {
  8. get
  9. {
  10. if (instance == null)
  11. {
  12. instance = FindObjectOfType(typeof(FlurryLogger)) as FlurryLogger;
  13. if (instance == null)
  14. {
  15. Debug.LogError("No gameObject with FlurryLogger component exists. Make sure to create a gameObject with FlurryLogger component");
  16. }
  17. }
  18. return instance;
  19. }
  20. }
  21. void Awake()
  22. {
  23. if (instance != null && instance != this)
  24. {
  25. Debug.LogWarning("FlurryLogger instance already exists on another gameObject. Destroying this gameObject FlurryLogger");
  26. Destroy(gameObject);
  27. return;
  28. }
  29. instance = this;
  30. DontDestroyOnLoad(gameObject);
  31. #if UNITY_EDITOR
  32. //return;
  33. #endif
  34. #if UNITY_IPHONE
  35. FlurryAgent.Instance.onStartSession("Q5ZJJ5X5P977V62V5HGT");
  36. #endif
  37. #if UNITY_ANDROID
  38. FlurryAgent.Instance.onStartSession("NTNQQFCVMY3KVM664YF9");
  39. #endif
  40. }
  41. void OnDestroy()
  42. {
  43. #if UNITY_IPHONE
  44. #endif
  45. #if UNITY_ANDROID
  46. FlurryAgent.Instance.onEndSession();
  47. #endif
  48. }
  49. public void GamePlayed()
  50. {
  51. if (FlurryAgent.Instance != null)
  52. {
  53. LogFlurryEvent("Games played");
  54. }
  55. }
  56. public void CouponWon()
  57. {
  58. if (FlurryAgent.Instance != null)
  59. {
  60. LogFlurryEvent("Coupons won");
  61. }
  62. else
  63. {
  64. Debug.LogError("Error Flurry");
  65. }
  66. }
  67. public void LifjaCoupone()
  68. {
  69. if (FlurryAgent.Instance != null)
  70. {
  71. LogFlurryEvent("Lifja Coupone", "id",SystemInfo.deviceUniqueIdentifier);
  72. }
  73. else
  74. {
  75. Debug.LogError("Error Flurry");
  76. }
  77. }
  78. public void DurexCoupone()
  79. {
  80. if (FlurryAgent.Instance != null)
  81. {
  82. LogFlurryEvent("Durex Coupone", "id",SystemInfo.deviceUniqueIdentifier);
  83. }
  84. else
  85. {
  86. Debug.LogError("Error Flurry");
  87. }
  88. }
  89. public void EndGame()
  90. {
  91. LogFlurryEvent("End Game", "id", SystemInfo.deviceUniqueIdentifier);
  92. }
  93. public void ShowVideoAd()
  94. {
  95. LogFlurryEvent("Show video ad", "id", SystemInfo.deviceUniqueIdentifier);
  96. }
  97. public void ShowFullScreenAd()
  98. {
  99. LogFlurryEvent("Show fullscreen ad", "id", SystemInfo.deviceUniqueIdentifier);
  100. }
  101. public void GameFinish(int dist, int packs, int score)
  102. {
  103. //LogFlurryEvent("GamesFinish", "meters", dist.ToString(), "packages", packs.ToString(), "score", score.ToString());
  104. LogFlurryEvent("Meters run", "meters", dist.ToString());
  105. LogFlurryEvent("Packages collected", "packages", packs.ToString());
  106. LogFlurryEvent("Score achieved", "score", score.ToString());
  107. }
  108. public void CapCode()
  109. {
  110. LogFlurryEvent("Cap code");
  111. }
  112. public void LogFlurryEvent (string eventName)
  113. {
  114. Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}'</color>", eventName));
  115. #if UNITY_EDITOR
  116. // return;
  117. #endif
  118. var parameters = new Dictionary<string,string>();
  119. parameters.Add("event data","empty");
  120. FlurryAgent.Instance.logEvent(eventName, parameters);
  121. }
  122. public void LogFlurryEvent (string eventName, params string[] keyValues)
  123. {
  124. //Debug.Assert (keyValues.Length % 2 == 0, "Make sure to pass key value pairs");
  125. Debug.Log(string.Format("<color=yellow>Sending a Flurry event '{0}' with the following parameters '{1}'</color>", eventName, string.Join(", ", keyValues)));
  126. #if UNITY_EDITOR
  127. // return;
  128. #endif
  129. var parameters = new Dictionary<string, string>();
  130. for (int i = 0; i < keyValues.Length; i += 2)
  131. {
  132. parameters[keyValues[i]] = keyValues[i + 1];
  133. }
  134. FlurryAgent.Instance.logEvent(eventName, parameters);
  135. }
  136. }