Skip to content

Analytic and NamedAnalytic



By implementing the Analytic or NamedAnalytic interfaces, you can quickly model events as real types. Tracking with these brings type safety whilst keeping implementation simple and flexible. With both interfaces, the key idea is to define a class that represents your event data as typed fields. NamedAnalytic goes one step further by providing a way to specify the event type name directly in the class, eliminating the need to specify it in the tracking call. Usage: Hoglin#track(String eventName, Analytic analytic) or Hoglin#track(NamedAnalytic analytic).

InterfaceUse WhenKey Idea
AnalyticUnknown event type until runtimeUse this if you have multiple events with the same data
NamedAnalyticKnown event typeAdds getEventType() so the instance supplies its own name

Choose Analytic when your event name is decided at runtime or when multiple events share the same data structure.

class PlayerAfkAnalytic implements Analytic {
final UUID playerUuid;
final String cause;
PlayerAfkAnalytic(final UUID playerUuid, final String cause) {
this.playerUuid = playerUuid;
this.cause = cause;
}
}
Hoglin hoglin = /** Your Hoglin instance */
boolean isAfk = /** Example runtime boolean */
if (isAfk) {
hoglin.track("afk_start", new PlayerAfkAnalytic(UUID.randomUUID(), "COMMAND"));
} else {
hoglin.track("afk_stop", new PlayerAfkAnalytic(UUID.randomUUID(), "COMMAND"));
}

Example event in Hoglin dashboard


Section titled “Using NamedAnalytic (recommended when possible)”

Choose NamedAnalytic when your event name is known at compile time.

public class PlayerJoinAnalytic implements NamedAnalytic {
final UUID playerUuid;
final String hostname;
final boolean isBedrock;
public PlayerJoinAnalytic(final UUID playerUuid, final String hostname, final boolean isBedrock) {
this.playerUuid = playerUuid;
this.hostname = hostName;
this.isBedrock = isBedrock;
}
@Override
public @NotNull String getEventType() { return "player_join"; }
}
Hoglin hoglin = /** Your Hoglin instance */;
hoglin.track(new PlayerJoinAnalytic(UUID.randomUUID(), "example.com:25565", false));

Example event in Hoglin dashboard


You can do a lot more with your data, visualizing and aggregating it in various ways. Follow this guide to learn more about Exploring Your Data in the Hoglin dashboard.


You can can use GSON’s @SerializedName annotation to apply a custom name to your parameters when they get serialized. This proves useful when using different naming schemes in your codebase and in Hoglin.

public class SomeAnalytic implements NamedAnalytic {
@SerializedName("useless_uuid") final UUID someParameterName;
public SomeAnalytic(final UUID someParameterName) {
this.someParameterName = someParameterName;
}
@Override
public @NotNull String getEventType() { return "something"; }
}
Hoglin hoglin = /** Your Hoglin instance */;
hoglin.track(new SomeAnalytic(UUID.randomUUID()));

Example event in Hoglin dashboard