Skip to content

Commit c6f07e4

Browse files
committed
Add Awake() method to initialize the tracker.
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.
1 parent 10f160f commit c6f07e4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

googleanalyticsv3.unitypackage

155 Bytes
Binary file not shown.

source/Plugins/GoogleAnalyticsV3/GoogleAnalyticsV3.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ pass a builder to the same method name in order to add custom metrics or
3131
custom dimensions to the hit.
3232
*/
3333
public class GoogleAnalyticsV3 : MonoBehaviour {
34-
34+
private string uncaughtExceptionStackTrace = null;
3535
private bool initialized = false;
36+
3637
public enum DebugMode {
3738
ERROR,
3839
WARNING,
@@ -70,6 +71,12 @@ public enum DebugMode {
7071
[Tooltip("If checked, the IP address of the sender will be anonymized.")]
7172
public bool anonymizeIP = false;
7273

74+
[Tooltip("Automatically report uncaught exceptions.")]
75+
public bool UncaughtExceptionReporting = false;
76+
77+
[Tooltip("Automatically send a launch event when the game starts up.")]
78+
public bool sendLaunchEvent = false;
79+
7380
[Tooltip("If checked, hits will not be dispatched. Use for testing.")]
7481
public bool dryRun = false;
7582

@@ -103,6 +110,35 @@ public enum DebugMode {
103110
private GoogleAnalyticsMPV3 mpTracker = new GoogleAnalyticsMPV3();
104111
#endif
105112

113+
void Awake() {
114+
InitializeTracker ();
115+
116+
if (sendLaunchEvent) {
117+
LogEvent("Google Analytics", "Auto Instrumentation", "Game Launch", 0);
118+
}
119+
120+
if (UncaughtExceptionReporting) {
121+
Application.RegisterLogCallback(HandleException);
122+
if (GoogleAnalyticsV3.belowThreshold(logLevel, GoogleAnalyticsV3.DebugMode.VERBOSE)) {
123+
Debug.Log ("Enabling uncaught exception reporting.");
124+
}
125+
}
126+
}
127+
128+
void Update() {
129+
if (uncaughtExceptionStackTrace != null) {
130+
LogException(uncaughtExceptionStackTrace, true);
131+
uncaughtExceptionStackTrace = null;
132+
}
133+
}
134+
135+
private void HandleException(string condition, string stackTrace, LogType type) {
136+
if (type == LogType.Exception) {
137+
uncaughtExceptionStackTrace = condition + "\n" + stackTrace
138+
+ UnityEngine.StackTraceUtility.ExtractStackTrace();
139+
}
140+
}
141+
106142
// TODO: Error checking on initialization parameters
107143
private void InitializeTracker() {
108144
if (!initialized) {

0 commit comments

Comments
 (0)