use of com.snowplowanalytics.snowplow.tracker.emitter.Emitter in project Terasology by MovingBlocks.
the class TelemetryUtils method fetchMetricAndSend.
/**
* Fetch metric in {@link org.terasology.context.Context} and send to the server.
* This method could be used in the modules.
* @param context The game context
* @param metricClass The class of the metric which we want to track
* @param nameSpace The name the class tracking this metric.
*/
public static void fetchMetricAndSend(Context context, Class metricClass, String nameSpace) {
Emitter emitter = context.get(Emitter.class);
Metrics metrics = context.get(Metrics.class);
TelemetryConfiguration telemetryConfiguration = context.get(TelemetryConfiguration.class);
if (emitter != null && metrics != null && telemetryConfiguration != null) {
Optional<Metric> metricOptional = metrics.getMetric(metricClass);
if (metricOptional.isPresent()) {
Metric metric = metricOptional.get();
Optional<Unstructured> unstructuredOptional = metric.getUnstructuredMetric();
if (unstructuredOptional.isPresent()) {
Unstructured unstructured = unstructuredOptional.get();
trackMetric(emitter, nameSpace, unstructured, metric, telemetryConfiguration);
}
}
} else {
logger.error("Emitter or metrics or telemetryConfiguration is not in context");
}
}
Aggregations