Skip to content

Commit

Permalink
Add Awake() method to initialize the tracker.
Browse files Browse the repository at this point in the history
Add methods for reporting some uncaught exceptions.
Add checkboxes to gav3 prefab for sending a launch event and for catching uncaught exceptions.

The Awake() method prevents some cases of null reference cases.

The exception logging isn't perfect as sometimes we don't get a full stack trace.
  • Loading branch information
baldwin628 committed Mar 1, 2015
1 parent 10f160f commit c6f07e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Binary file modified googleanalyticsv3.unitypackage
Binary file not shown.
38 changes: 37 additions & 1 deletion source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c6f07e4

Please sign in to comment.