|
@@ -0,0 +1,68 @@
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using KairoEngine.Core;
|
|
|
+using KairoEngine.Core.ModuleSystem;
|
|
|
+using Sirenix.OdinInspector;
|
|
|
+using mixpanel;
|
|
|
+
|
|
|
+namespace KairoEngine.Analytics
|
|
|
+{
|
|
|
+ [Serializable, HideReferenceObjectPicker]
|
|
|
+ public class AnalyticsModule : GameModuleBase
|
|
|
+ {
|
|
|
+ public override string name => "Analytics Module";
|
|
|
+
|
|
|
+ [FoldoutGroup("@name")] public string mixpanelAPIToken = "";
|
|
|
+ [FoldoutGroup("@name")] public bool trackEvents = true;
|
|
|
+ [FoldoutGroup("@name")] public bool debugEvents = true;
|
|
|
+ [FoldoutGroup("@name")] public bool clearEventsOnStart = false;
|
|
|
+
|
|
|
+ public AnalyticsModule(GameConfig config) : base(config)
|
|
|
+ {
|
|
|
+ this.gameConfig = config;
|
|
|
+ this.className = this.GetType().AssemblyQualifiedName;
|
|
|
+ this.typeName = "AnalyticsModule";
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Load(Transform parent)
|
|
|
+ {
|
|
|
+ if(mixpanelAPIToken == "") Debug.LogWarning("Missing Mixpanel API Token. Please configure Analytics Module in GameConfig.");
|
|
|
+ else Mixpanel.SetToken(mixpanelAPIToken);
|
|
|
+ GameObject obj = GameObject.Instantiate(new GameObject(), parent);
|
|
|
+ obj.name = "Analytics";
|
|
|
+ AnalyticsComponent analytics = obj.AddComponent<AnalyticsComponent>();
|
|
|
+ analytics.trackEvents = trackEvents;
|
|
|
+ analytics.debugEvents = debugEvents;
|
|
|
+ analytics.clearEventsOnStart = clearEventsOnStart;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Reset()
|
|
|
+ {
|
|
|
+ mixpanelAPIToken = "";
|
|
|
+ trackEvents = true;
|
|
|
+ debugEvents = true;
|
|
|
+ clearEventsOnStart = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Destroy() { }
|
|
|
+
|
|
|
+ public static AnalyticsModule JSONToAnalyticsModule(string data)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return JsonUtility.FromJson<AnalyticsModule>(data);
|
|
|
+ }
|
|
|
+ catch (System.Exception e)
|
|
|
+ {
|
|
|
+ Debug.LogError($"Could not deserialize AnalyticsModule: \n{e}");
|
|
|
+ return new AnalyticsModule(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnBeforeSerialize(ObjectSerializer serializer) { }
|
|
|
+ public override void OnBeforeDeserialize(ObjectSerializer serializer) { }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|