All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hu.ponte.respresso.plugin.gradle.GoogleAnalyticsHandler Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package hu.ponte.respresso.plugin.gradle;

import com.brsanthu.googleanalytics.GoogleAnalytics;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class GoogleAnalyticsHandler {

    public static String appVersion = "0.0.2";

    public static GoogleAnalytics ga = GoogleAnalytics.builder()
            .withTrackingId("UA-129036545-2")
            .withAppName("Android Respresso client")
            .withAppVersion(appVersion)
            .build();

    public static void sendError(Throwable e, Boolean isExceptionFatal) {
        StringBuilder error = new StringBuilder();

        for (StackTraceElement err : e.getStackTrace())
            error.append(err.getClassName())
                    .append(".")
                    .append(err.getMethodName())
                    .append(".")
                    .append(err.getFileName())
                    .append(":")
                    .append(err.getLineNumber())
                    .append("\n");

        sendError(error.toString(), isExceptionFatal);
    }

    public static void sendError(String error, Boolean isExceptionFatal) {
        String host = "Unknown Android host";
        try {
            host = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        ga.exception().clientId(host).applicationId(appVersion).exceptionFatal(isExceptionFatal)
                .exceptionDescription(error)
                .send();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy