Search in sources :

Example 1 with Emitter

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");
    }
}
Also used : Emitter(com.snowplowanalytics.snowplow.tracker.emitter.Emitter) TelemetryConfiguration(org.terasology.config.facade.TelemetryConfiguration) Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) Metric(org.terasology.telemetry.metrics.Metric)

Aggregations

Emitter (com.snowplowanalytics.snowplow.tracker.emitter.Emitter)1 Unstructured (com.snowplowanalytics.snowplow.tracker.events.Unstructured)1 TelemetryConfiguration (org.terasology.config.facade.TelemetryConfiguration)1 Metric (org.terasology.telemetry.metrics.Metric)1