Some analytic events are recorded out-of-box:
- Activity/Fragment changes
- Focus changes
- Clicked views
- Application crashes
- For everything else, custom events can be used
Custom event
A simple custom event can be created by calling:
public static void TrackCustomEvent(string name, Dictionary<string, string> eventProperties = null)
Custom event also accepts a dictionary of string key/values as event properties.
Navigation event
Screen/navigation transitions can be manually tracked by calling:
public enum NavigationEventType
{
Enter,
Exit
}
public static void TrackNavigationEvent(string identifier, NavigationEventType type = NavigationEventType.Enter)
where the type
could flag the event as either enter
or exit
of the navigation controller.
Timed event
Duration of any time-sensitive or long-running actions in the application can be measured using timed events. A timed event can be started by using the following:
public static string StartTimedCustomEvent(string name, Dictionary<string, string> eventProperties = null)
This will not send out any events but will return a unique eventId
that needs to be stored and it is then used to stop/cancel a custom timed event. To send out an event with a duration, stop needs to be called:
public static void TrackTimedCustomEvent(string eventId, Dictionary<string, string> eventProperties = null)
with corresponding eventId
obtained from StartTimedCustomEvent
.
Properties set in start will be merged with properties set in stop/cancel. Properties from stop/cancel have a higher priority and will rewrite conflicting properties from the start.
In case a given action failed TrackTimedCustomEventCancel()
can be called instead of TrackTimedCustomEvent()
it has an extra field used for the reason of any failure:
public static void TrackTimedCustomEventCancel(string eventId, string reason = null, Dictionary<string, string> eventProperties = null)
Typical use of timed event might look like this:
timedEventId = Smartlook.Analytics.StartTimedCustomEvent("TIMED_EVENT", new Dictionary<string, string>() { { "PROP_1", "START_VALUE_1" }, { "PROP_2", "START_VALUE_2" } });
System.Threading.Thread.Sleep(1000);
Smartlook.Analytics.TrackTimedCustomEvent(timedEventId, new Dictionary<string, string>() { { "PROP_1", "TRACK_VALUE_1" } });
In this case the TIMED_EVENT
will have duration a property set to circa 1000ms.
Global event properties
Extra properties can be attached to every event, these properties are called global event properties. Global event properties can be set by calling:
public enum PropertyOptions : uint
{
Defaults = 0,
Immutable = 1 << 0
}
public static void SetGlobalEventProperty(string name, string value, PropertyOptions options = PropertyOptions.Defaults)
Smartlook.Analytics.SetGlobalEventProperty("prop1", "value1");
Smartlook.Analytics.SetGlobalEventProperty("immutable-prop", "immutable value", Smartlook.Analytics.PropertyOptions.Immutable);
Properties set to be immutable have the highest priority and once set they cannot be overridden (only removed).
Global event properties have higher a priority so in the merging process they will override custom properties with the same key.
Remove global event properties
A global property with a given key can be removed:
public static void RemoveGlobalEventProperty(string name)
Or all global event properties can be removed at once:
public static void ClearGlobalEventProperties()
Global event properties are stored until they are not removed or the app is uninstalled.
Event tracking modes
It can be beneficial to disable some automatically detected events due to security or usability reasons. This can be done using event tracking modes.
Tracking modes are defined in the EventTrackingMode
enumeration:
FullTracking
: this a default state. SDK tracks all automatically detected events along with all user defined events.IgnoreUserInteraction
: automatically detected events will not be tracked. User defined events are still enabled.IgnoreNavigationInteraction
: disables automatically detected navigation events. User defined ones are still being sent.IgnoreRageClicks
: disables automatic detection and tracking of rage click events.NoTracking
: no automatically detected events are tracked. Only user defined events are still tracked.
Set event tracking modes
Single or a combination of event tracking modes can be set any time after SDK setup by using the following:
public static void SetEventTrackingMode(EventTrackingMode eventTrackingMode)
public static void SetEventTrackingModes(EventTrackingMode[] eventTrackingModes)
Next reading
- Further info about event tracking modes could be found in the Event Tracking conceptual document.
- Also take a look at the pin code keyboard sample, demonstrating usage of analytic event modes.
List event tracking modes
All currently active event tracking modes can be listed by calling:
public static EventTrackingMode[] CurrentEventTrackingModes