snowplow / snowplow-java-tracker

Snowplow event tracker for Java. Add analytics to your Java desktop and server apps, servlets and games. (See also: snowplow-android-tracker)
http://snowplowanalytics.com
Apache License 2.0
24 stars 36 forks source link

Return eventId from Tracker.track() (close #304) #310

Closed mscwilson closed 2 years ago

mscwilson commented 2 years ago

For issue #304.

These changes remove two inappropriate fields from Events, remove the Hamcrest dependency, and add a return type to Tracker.track().

Bad stuff

Previously, eventId was an Event field. Users were able to provide their own event ID when building an Event, or one would be generated automatically. The eventId was passed to the payload on TrackerPayload creation, when Event.getPayload() was called during Tracker.track() - or before PR #293, during event sending by the Emitter.

Snowplow pipelines rely on eventIds being unique; allowing it to be set manually was very risky.

Users were also still able to set deviceCreatedTimestamp, a legacy option from before the introduction of trueTimestamp. TrueTimestamp is designed specifically for users to set their own timestamp. Aside from that, setting deviceCreatedTimestamp then means it referred to when the Event was built, which isn't necessarily when it's tracked.

New stuff

EventId and deviceCreatedTimestamp are now fields of TrackerPayload, and are generated automatically on TrackerPayload initialisation. DeviceCreatedTimestamp now more accurately describes the time at which Tracker.track() was called.

Previously, users could access an Event's eventId using Event.getEventId() for use elsewhere in their application. We now return the eventId from Tracker.track(). If the payload was lost because the Emitter buffer was full, null is returned instead.

I also removed the Hamcrest test dependency, which was only used in a couple of places.