diff --git a/googleanalyticsv3.unitypackage b/googleanalyticsv3.unitypackage index c5b7d5e..f0b02fc 100644 Binary files a/googleanalyticsv3.unitypackage and b/googleanalyticsv3.unitypackage differ diff --git a/source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsV3.cs b/source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsV3.cs index 50b1f2d..882356e 100755 --- a/source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsV3.cs +++ b/source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsV3.cs @@ -31,8 +31,9 @@ pass a builder to the same method name in order to add custom metrics or custom dimensions to the hit. */ public class GoogleAnalyticsV3 : MonoBehaviour { - + private string uncaughtExceptionStackTrace = null; private bool initialized = false; + public enum DebugMode { ERROR, WARNING, @@ -70,6 +71,12 @@ public enum DebugMode { [Tooltip("If checked, the IP address of the sender will be anonymized.")] public bool anonymizeIP = false; + [Tooltip("Automatically report uncaught exceptions.")] + public bool UncaughtExceptionReporting = false; + + [Tooltip("Automatically send a launch event when the game starts up.")] + public bool sendLaunchEvent = false; + [Tooltip("If checked, hits will not be dispatched. Use for testing.")] public bool dryRun = false; @@ -103,6 +110,35 @@ public enum DebugMode { private GoogleAnalyticsMPV3 mpTracker = new GoogleAnalyticsMPV3(); #endif + void Awake() { + InitializeTracker (); + + if (sendLaunchEvent) { + LogEvent("Google Analytics", "Auto Instrumentation", "Game Launch", 0); + } + + if (UncaughtExceptionReporting) { + Application.RegisterLogCallback(HandleException); + if (GoogleAnalyticsV3.belowThreshold(logLevel, GoogleAnalyticsV3.DebugMode.VERBOSE)) { + Debug.Log ("Enabling uncaught exception reporting."); + } + } + } + + void Update() { + if (uncaughtExceptionStackTrace != null) { + LogException(uncaughtExceptionStackTrace, true); + uncaughtExceptionStackTrace = null; + } + } + + private void HandleException(string condition, string stackTrace, LogType type) { + if (type == LogType.Exception) { + uncaughtExceptionStackTrace = condition + "\n" + stackTrace + + UnityEngine.StackTraceUtility.ExtractStackTrace(); + } + } + // TODO: Error checking on initialization parameters private void InitializeTracker() { if (!initialized) {