Overriding Timestamps
By default, when Tracking with Maps or using the
Analytic/NamedAnalytic interfaces, the timestamp of the
event is automatically set to the time at which the Hoglin#track call is made. But, in some situations, you may want
to manually override this and set your own timestamp for an event. Let’s explore how to do this.
Manually constructing a RecordedAnalytic
Section titled “Manually constructing a RecordedAnalytic”When tracking with maps or the interfaces, both will dumb down to a RecordedAnalytic under the hood.
This is a class containing the event name, properties, and notably a timestamp. Typically, the timestamp is defaulted
to the current time upon construction. However, we expose this class, along with a method for tracking with it:
Hoglin#track(RecordedAnalytic<?> analytic), providing a way for you to set your own timestamp.
Full code example
Section titled “Full code example”// Tracking with maps
Hoglin hoglin = /** Your Hoglin instance */;
final RecordedAnalytic<Map<String, Object>> analytic = new RecordedAnalytic<>( "example_event", Instant.now().minus(10, ChronoUnit.MINUTES), Map.of( "example_string", "test", "example_integer", 123 ));
hoglin.track(analytic);// Using the Analytic/NamedAnalytic interface
class ExampleAnalytic implements NamedAnalytic { final String exampleString; final int exampleInteger;
ExampleAnalytic(final String exampleString, final int exampleInteger) { this.exampleString = exampleString; this.exampleInteger = exampleInteger; }
@Override public @NotNull String getEventType() { return "example_event"; }}
Hoglin hoglin = /** Your Hoglin instance */;
final RecordedAnalytic<ExampleAnalytic> analytic = new RecordedAnalytic<>( "example_event", Instant.now().minus(10, ChronoUnit.MINUTES), new ExampleAnalytic("test", 123));
hoglin.track(analytic);// Tracking with maps
val hoglin: Hoglin = /** Your Hoglin instance */
val analytic = RecordedAnalytic( "example_event", Instant.now().minus(10, ChronoUnit.MINUTES), mapOf( "example_string" to "test", "example_integer" to 123 ))
hoglin.track(analytic)// Using the Analytic/NamedAnalytic interface
class ExampleAnalytic( val exampleString: String, val exampleInteger: Int) : NamedAnalytic { override fun getEventType(): String = "example_event"}
val hoglin: Hoglin = /** Your Hoglin instance */
val analytic = RecordedAnalytic( "example_event", Instant.now().minus(10, ChronoUnit.MINUTES), ExampleAnalytic("test", 123))
hoglin.track(analytic)This will track the example_event with a timestamp of 10 minutes ago.