Auto Events
The Auto Events module is a powerful analytics tracking system that automatically captures user interactions and screen views in Android applications. It provides a seamless way to track user behavior without requiring manual event logging.
Features
1. Automatic User Interaction Tracking
- Tracks user interactions such as clicks, taps, and gestures
- Configurable tracking predicates to filter which interactions to track
2. Screen View Tracking
- Automatically tracks Activity and Fragment screen views
- Maintains screen stack information for navigation context
- Captures screen hierarchy and navigation flow
3. Impression Tracking
- Tracks when views become visible to users
- Configurable visibility thresholds and time requirements
- Special support for RecyclerView items
- Customizable impression tracking data
Setup
Initialization
Initialize the Auto Events module in your Application class:
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
val config = AutoEventsConfiguration.Builder()
.trackUserInteractions() // Enable user interaction tracking
.trackImpressions() // Enable impression tracking
.build()
AutoEvents.enable(config, this)
}
}
View Configuration
Configure views for tracking using extension functions:
// Enable auto tracking for a view
view.shouldAutoTrack(true)
// Set section information
view.section("home_screen")
view.sectionGroup("main_navigation")
// Set element name
view.elementName("login_button")
// Configure impression tracking
view.setImpressionTrackingData(
ImpressionTrackingData(
trackingId = "unique_id",
parameters = mapOf("type" to "featured_item")
)
)
Configure Fragment/Activity for tracking using TrackableScreen interface:
class MyFragment: Fragment(), TrackableScreen {
// custom screen id
override val screenId: String = "my_fragment_id"
// additional properties, ids
override val additionalData: TrackableScreen.AdditionalData = TrackableScreen.AdditionalData(
additionalProperties = mapOf("key" to "value"),
additionalIds = listOf("id1", "id2")
)
}
RecyclerView Impression Tracking
For RecyclerViews, use the special impression tracking:
recyclerView.autoTrackItemView(
config = ImpressionTrackingConfig(
minVisibleTimeMs = 1000, // Minimum time view must be visible
minVisibleThreshold = 0.5f // Minimum visibility percentage
)
)
Configuration Options
AutoEventsConfiguration
The configuration builder provides several options:
val config = AutoEventsConfiguration.Builder()
.trackUserInteractions() // Enable user interaction tracking
.disableUserInteractionTracking() // Disable user interaction tracking
.trackImpressions() // Enable impression tracking
.disableImpressionTracking() // Disable impression tracking
.actionTrackingPredicate(customPredicate) // Custom tracking predicate
.build()
Custom Tracking Predicate
Implement custom logic to determine which views should be tracked:
class CustomActionTrackingPredicate : ActionTrackingPredicate {
override fun shouldTrack(view: View): Boolean {
// Your custom logic here
return view is CustomButton
}
}
Tracked Events
This library automatically tracks the following events:
page_view
Tracked when navigating through activities/fragments. Developers can provide custom screen IDs by implementing
the TrackableScreen interface.
| field name | type | optional | value |
|---|---|---|---|
element.id | String | yes | custom ID defined by developer when implementing TrackableScreen |
element.type | String | no | activity or fragment |
element.sequence | Int | yes | number of opened screen |
element.class | String | no | activity/fragment class name |
sources_info | [Array] | no | last 3 screen info |
additional_properties | [String: String] | yes | additional data provided by developer when implementing TrackableScreen |
additional_ids | [String: String] | yes | additional ids provided by developer when implementing TrackableScreen |
Example of event
{
"data": {
"sources_info": [
{
"class": "com.picsart.createflow.dolphin3.presenter.dolphincontainerfragment",
"id": "create_flow_screen",
"sid": "9d2cc3c2-573e-3600-ab2b-3978959e560d"
},
{
"class": "com.picsart.chooser.chooseractivity",
"sid": "27e1ccd2-736b-3575-b050-79f5594ba114"
},
{
"class": "com.picsart.studio.editor.main.editoractivity",
"id": "editor_screen",
"sid": "ffd07962-3dcf-333e-be17-8ffda0b3fa41"
}
],
"element": {
"class": "com.socialin.android.photo.effectsnew.fragment.effectfragment",
"id": "effects_screen",
"type": "fragment"
}
},
"event_id": "7bd326a1-cc6b-48b0-97d5-31688ed3a1ae",
"sub_sids": {
"main_screen": "727c07fa-147c-3ac3-841a-128e3be86355",
"create_flow_screen": "9d2cc3c2-573e-3600-ab2b-3978959e560d",
"com.picsart.chooser.ChooserActivity": "27e1ccd2-736b-3575-b050-79f5594ba114",
"editor_screen": "ffd07962-3dcf-333e-be17-8ffda0b3fa41",
"effects_screen": "9d4f1c3d-9b63-35aa-8558-7d18c57f85ff"
}
}
click
Tracked when a user taps on a view.
| field name | type | optional | value |
|---|---|---|---|
element.id | String | yes |
|
element.value | String | yes | Button localized text |
element.type | String | no |
|
parent_info | [String: String] | no | parent fragment/activity info |
sources_info | [Array] | no | last 3 screen info |
Example of event
{
"data": {
"sources_info": [
{
"class": "com.picsart.createflow.dolphin3.presenter.dolphincontainerfragment",
"id": "create_flow_screen",
"sid": "9d2cc3c2-573e-3600-ab2b-3978959e560d"
},
{
"class": "com.picsart.chooser.chooseractivity",
"sid": "27e1ccd2-736b-3575-b050-79f5594ba114"
}
],
"parent_info": {
"class": "com.picsart.studio.editor.main.editoractivity",
"id": "editor_screen"
},
"element": {
"id": "btn_close",
"type": "button"
}
},
"event_id": "fc03568d-e916-4424-be6f-8575f23e0017",
"event_type": "click",
"sub_sids": {
"main_screen": "727c07fa-147c-3ac3-841a-128e3be86355",
"create_flow_screen": "9d2cc3c2-573e-3600-ab2b-3978959e560d",
"com.picsart.chooser.ChooserActivity": "27e1ccd2-736b-3575-b050-79f5594ba114",
"editor_screen": "ffd07962-3dcf-333e-be17-8ffda0b3fa41"
}
}
Disable Tracking
To disable auto events tracking:
AutoEvents.disable()