Snowplow Java Tracker 0.4.0 released
We’re excited to announce another release of the Snowplow Java Tracker version 0.4.0.
This release makes some significant updates to the Java Tracker. The main objective for this release was to bring the Tracker much closer in functional terms to the Python Tracker. In doing so, we’ve added new
Subject classes along with various changes to the existing
Some of the other more notable features in this release is support for POST requests, sending of events asynchronous and event queueing. I’ll be covering everything mentioned above in more detail:
- Structural improvements
- The Emitter class
- The TrackerPayload class
- The Subject class
- Google Guava Preconditions
- Tracker class constructor
- Optional context and timestamp
It’s important to first mention the structural changes that have come with this release, since using this version breaks compatibility with older versions of the Tracker. Here is a list of the changes made:
ContractManagerclass have been removed
TrackerCclass is replaced with
PayloadMapinterface is replaced with
PayloadMapCclass is replaced with
- There are four new enums:
DevicePlatform- to specify the build
emitter.BufferOption- to specify buffer queue should behave
emitter.HttpMethod- to choose between sending GET or POST requests
emitter.RequestMethod- to choose how events should be sent
Emitter lets you create multiple instances of it so you can send events to many collectors if you want. The
Emitter class supports sending event data via GET or POST requests although note that Snowplow will only be supporting POST data in a future release. This can be set using the
Events by default are buffered until they reach 10 events and are then sent in a batch. We now support sending events either in a batch or instantly upon being tracked.
BufferOption is used to let you switch between the two options.
You can also now choose whether events should be sent asynchronously, using the
Emitter by default, sends events synchronously, using GET requests and with a buffer size of 10 events.
Here you can find an example of all the options available:
TrackerPayload class implements the new
Payload interface. It lets you create a
Payload similar to a
HashMap but made specifically for tracking events.
Currently, it’s used by the
Tracker class to create each tracking payload, but in the next release, we’ll add the ability to add your own
Payload into an Unstructured Tracking Event.
Subject class functions similar to its Python counterpart: an instance of the
Subject class represents a user who is performing an event in the Subject-Verb-Direct Object model proposed in our Snowplow event grammar. Although you can create a
Tracker instance without a
Subject, you won’t be able to add information such as user ID and timezone to your events without one.
Here’s an example that shows you how to track more that one user using the
It is also possible to set the subject during Tracker initialization:
We’ve removed the
ContractManager class and replaced it with Google’s Precondition check. We check to make sure that trackers are not sending null or empty string parameters when tracking events.
For example, if were to track a page view without setting the
We would see an exception sent:
Tracker class, you’ve seen the examples from the previous posts where we’ve changed the
Tracker constructor. To formally mention the changes, we now provide four options for the
Under the hood, the way we construct each specific tracking event is done within tracker class. Previously, the
PayloadC class would handle this.
Similar to the
Tracker constructor, we wanted to make it optional for you to set certain parameters without any magic numbers or null values involved.
Each Tracker now has multiple method signatures letting you send a context and/or timestamp depending on your own needs. Here are the method signatures:
The TransactionItem class also has a method signature for an optional context as well:
With the new classes being created, we’ve also added more unit tests to verify them. Have a look at some of them for more examples on how they are being used.
Parameter classes have both been updated to support all the tracking parameters that would be used. This will be more useful when you start creating your own
Please get in touch if you need help setting up the Snowplow Java Tracker or want to suggest a new feature. The Snowplow Java Tracker is rapidly evolving, so please feel free to raise an issue if you find any bugs or have any feature requests.
For more details on this release, please check out the 0.4.0 Release Notes on GitHub.