mirror of https://github.com/tasks/tasks
Rename tracker to firebase
parent
29f0d5b5b8
commit
3a13d56060
@ -0,0 +1,8 @@
|
|||||||
|
package org.tasks.analytics
|
||||||
|
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class Firebase @Inject constructor() {
|
||||||
|
fun reportException(t: Throwable) = Timber.e(t)
|
||||||
|
}
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package org.tasks.analytics;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public class Tracker {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public Tracker() {}
|
|
||||||
|
|
||||||
public void reportException(Throwable t) {
|
|
||||||
Timber.e(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package org.tasks.analytics
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Bundle
|
||||||
|
import com.android.billingclient.api.BillingClient.BillingResponse
|
||||||
|
import com.crashlytics.android.Crashlytics
|
||||||
|
import com.google.firebase.analytics.FirebaseAnalytics
|
||||||
|
import io.fabric.sdk.android.Fabric
|
||||||
|
import org.tasks.billing.BillingClientImpl
|
||||||
|
import org.tasks.injection.ApplicationScope
|
||||||
|
import org.tasks.injection.ForApplication
|
||||||
|
import org.tasks.preferences.Preferences
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ApplicationScope
|
||||||
|
class Firebase @Inject constructor(@ForApplication context: Context?, preferences: Preferences) {
|
||||||
|
|
||||||
|
private var enabled: Boolean = preferences.isTrackingEnabled
|
||||||
|
private var analytics: FirebaseAnalytics? = null
|
||||||
|
|
||||||
|
fun reportException(t: Throwable?) {
|
||||||
|
Timber.e(t)
|
||||||
|
if (enabled) {
|
||||||
|
Crashlytics.logException(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reportIabResult(@BillingResponse response: Int, sku: String?) {
|
||||||
|
if (!enabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val bundle = Bundle()
|
||||||
|
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, sku)
|
||||||
|
bundle.putString(FirebaseAnalytics.Param.SUCCESS, BillingClientImpl.BillingResponseToString(response))
|
||||||
|
analytics!!.logEvent(FirebaseAnalytics.Event.ECOMMERCE_PURCHASE, bundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (enabled) {
|
||||||
|
analytics = FirebaseAnalytics.getInstance(context!!)
|
||||||
|
analytics?.setAnalyticsCollectionEnabled(true)
|
||||||
|
Fabric.with(context, Crashlytics())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,55 +0,0 @@
|
|||||||
package org.tasks.analytics;
|
|
||||||
|
|
||||||
import static org.tasks.billing.BillingClientImpl.BillingResponseToString;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import com.android.billingclient.api.BillingClient.BillingResponse;
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics.Event;
|
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics.Param;
|
|
||||||
import io.fabric.sdk.android.Fabric;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import org.tasks.injection.ApplicationScope;
|
|
||||||
import org.tasks.injection.ForApplication;
|
|
||||||
import org.tasks.preferences.Preferences;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
@ApplicationScope
|
|
||||||
public class Tracker {
|
|
||||||
|
|
||||||
private static boolean enabled;
|
|
||||||
|
|
||||||
private final FirebaseAnalytics analytics;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public Tracker(@ForApplication Context context, Preferences preferences) {
|
|
||||||
enabled = preferences.isTrackingEnabled();
|
|
||||||
if (enabled) {
|
|
||||||
analytics = FirebaseAnalytics.getInstance(context);
|
|
||||||
analytics.setAnalyticsCollectionEnabled(true);
|
|
||||||
Fabric.with(context, new Crashlytics());
|
|
||||||
} else {
|
|
||||||
analytics = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reportException(Throwable t) {
|
|
||||||
Timber.e(t);
|
|
||||||
if (enabled) {
|
|
||||||
Crashlytics.logException(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reportIabResult(@BillingResponse int response, String sku) {
|
|
||||||
if (!enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(Param.ITEM_ID, sku);
|
|
||||||
bundle.putString(Param.SUCCESS, BillingResponseToString(response));
|
|
||||||
analytics.logEvent(Event.ECOMMERCE_PURCHASE, bundle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue