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
foregroundTimeoutperiod, the session will be updated and a new session started
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:
tracker.pauseEventTracking()and to start collection again run
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.
To get the latest version please download from here. To install the app you will need to allow installation from sources other than the Google Play Store.
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:
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.
For help on integrating the application please have a look at the setup and integration guides.
Feel free to get in touch or raise an issue in the Android Tracker’s issues on GitHub!