# Automatic Event Tracking
# 1. Enable Auto-tracking
You can call EnableAutoTrack
to enable the auto-tracking function:
// auto-tracking events type
public enum AUTO_TRACK_EVENTS
{
NONE = 0,
APP_START = 1 << 0,
APP_END = 1 << 1,
APP_CRASH = 1 << 4,
APP_INSTALL = 1 << 5,
ALL = APP_START | APP_END | APP_INSTALL | APP_CRASH
}
More details about auto-tracking events:
- APP_START: Open APP, including activiting APP and resuming APP from the background
- APP_END: Close APP, including disabling the APP and calling in the background while tracking the duration of the enabling process
- APP_CRASH: Record crash information when the APP crashes
- APP_INSTALL: Record APP installation
- ALL: All types above
// enable all auto-tracking events
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL);
// enable Open and Close events
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.APP_START | AUTO_TRACK_EVENTS.APP_END);
Note: If you need to set a custom distinct ID or super properties, be sure to set them before enabling auto-tracking events
About APP_CRASH, if you only want to track Objective-C and Java exceptions on iOS and Android, but not C# exceptions, you can configure disabled information by adding ta_public_config.xml in the Resources directory in v2.3.1 and above versions.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- ThinkingAnalytics disable C# Exception -->
<bool name="DisableCSharpException">true</bool>
</resources>
# 2. Set the Properties of Auto-tracking Events
Starting from v2.2.4, you can enable auto-tracking by calling EnableAutoTrack
with properties that need to be tracked.
// enable aotu-tracking with properties
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL, new Dictionary<string, object>() {
{"custom_key", "custom_value"}
});
You can also call SetAutoTrackProperties
to set properties for auto-tracking events.
Note: SetAutoTrackProperties
will not enable auto-tracking, you need to call EnableAutoTrack
at the same time.
// set properties for a auto-tracking event
ThinkingAnalyticsAPI.SetAutoTrackProperties(AUTO_TRACK_EVENTS.APP_START, new Dictionary<string, object>()
{
{"start_key", "start_value"}
});
// set properties for auto-tracking events
ThinkingAnalyticsAPI.SetAutoTrackProperties(AUTO_TRACK_EVENTS.APP_INSTALL | AUTO_TRACK_EVENTS.APP_CRASH, new Dictionary<string, object>()
{
{"install_crash_key", "install_crash_value"}
});
// enable auto-tracking for all
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL);
# 3. Set Auto-tracking Event Callbacks
Starting from v2.4.0, it supports setting auto-tracking event callbacks to set properties in time, or execute code when events are triggered. To set auto-tracking event callback, you need to create a new class and implement the interface IAutoTrackEventCallback
, and override the method public Dictionary<string, object> AutoTrackEventCallback(int type, Dictionary<string, object>properties)
. The return value of this method is the properties that need to be set. Then call EnableAutoTrack
to pass in the auto-tracking event callback object.
// 1. implement auto-tracking callback
public class AutoTrackECB : IAutoTrackEventCallback
{
public Dictionary<string, object> AutoTrackEventCallback(int type, Dictionary<string, object>properties)
{
return new Dictionary<string, object>()
{
{"AutoTrackEventProperty", DateTime.Today}
};
}
}
// 2. enable auto-tracking, and set callback
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL, new AutoTrackECB());