We are pleased to announce the release of the Snowplow Android Tracker version 0.5.0. The Tracker has undergone a series of performance improvements, plus the addition of client-side sessionization.
This release post will cover the following topics:
- Client-side sessionization
- Tracker performance
- Event building
- Other changes
- Demo app
- Getting help
This release lets you add a new
client_session context to each of your Snowplow events, allowing you to easily group events from a single user into a single session. This functionality can be activated by passing in the following builder commands to the Tracker creation step:
Once sessionization has been turned on several things will begin to happen:
client_sessioncontext will be appended to each event that is sent
- A polling check will be started to check whether or not the session has timed out
- You can configure how often to check with the
- If your app is in the foreground and no events have been sent for the
foregroundTimeoutperiod, the session will be updated and a new session started
- There is a separate timeout if your application is detected to be in the background
- You can configure how often to check with the
- Each time the session information is updated it is stored locally in a private file which should persist for the life of the application
- Each time an event is sent from the Tracker, both timeouts for the session are reset
Session information should survive for the life of the application, i.e. until it is uninstalled from the Android device.
An important note here is that we cannot detect if the application is in the background or not from a library standpoint. You will have to update your applications
onResume() functions to manually flag this change. The following samples can be copied into an application activity to set the background state of the application for the session checker:
If you know of a better way to detect this state in Android please let us know in the comments below!
Several updates have been made to how the Tracker functions to improve performance and to reduce the memory footprint of the Tracker.
Firstly, events sent from the Tracker are now sent asynchronously over many threads as opposed to sequentially on a single background thread. This has drastically improved the speed at which the Tracker can send events to Snowplow collectors.
Secondly, we have also improved the speed at which events are added and removed from the local SQLite database by enabling
writeAheadLogging. This means that we can now read and write to the database at the same time; this prevents contention between adding events to the outbound queue and emitting them to a collector.
This means the Tracker now processes as much as possible using a concurrent model, orchestrated by a configurable thread pool that you can define the size of:
Note: the thread pool must be at least 2 in size due to the nature of the Emitter functioning as a singleton.
Please also note that if you make the thread pool too large it can have serious performance implications. An issue was discovered with using the RxJava default I/O scheduler in that it would grow the thread pool on demand, sometimes up to 500 threads, this in turn rendered the demonstration applications UI unresponsive and then subsequently crashed the application. See this ticket for more information.
Finally, we have also implemented an important fix to reduce the library’s memory footprint. We now nullify the large arrays of events fetched from the database for sending as soon as they are no longer required, allowing the Android garbage collector to work much more efficiently.
Alongside the performance updates we have made a fundamental change to how all the
tracker.track functions operate. In place of many different types of
track functions, we now have a single
track function which can take different types of
Events. These events are now built using the Builder pattern.
To illustrate lets look at how we were tracking a page view event in version 0.4.0:
For events like an Ecommerce Transaction it quickly becomes difficult to reason about:
Here is a page view in version 0.5.0:
And here is the ecommerce event:
The new Builder pattern is slightly more verbose but the readbility is greatly improved. Also, you no longer have to pass in
null entries for fields you don’t want to populate.
We have also:
- Added a function in the Tracker which allows you to instantly turn off all tracking and event collection
tracker.pauseEventTracking()and to start collection again run
- Added the ability to set a custom event id for any event using the Builder option
- Fixed a bug whereby a needed field was not being set for the
- Fixed a bug whereby the Emitter’s send operation might not time out as required (#138)
The demonstration app has also undergone a few minor updates. We now have a radio button group which will allow you to switch of all data collection as noted in this ticket. Located under the
Collection header, simply press
OFF to toggle this setting.
Metrics header we now also deplay how many sessions the Tracker has observed; you can see that it will indeed survive application and phone restarts.
You can find the updated Android Tracker documentation on our wiki.
As part of this release we have updated our tutorials to help Android developers integrate the Tracker into their apps:
- Guide to integrating the tracker
- Guide to setting up a test environment
- Walkthrough of our Android demo app
You can find the full release notes on GitHub as Snowplow Android Tracker v0.5.0 release.
The Android Tracker is still a young project and we will be working hard with the community to improve it over the coming weeks and months; in the meantime, do please share any user feedback, feature requests or possible bugs.