Log What's New events

pull/996/head
Alex Baker 4 years ago
parent ebe56e7ce5
commit 1d7c75097c

@ -2,6 +2,7 @@ package org.tasks.analytics
import android.content.Context
import android.os.Bundle
import androidx.annotation.StringRes
import com.android.billingclient.api.BillingClient.BillingResponse
import com.crashlytics.android.Crashlytics
import com.google.firebase.analytics.FirebaseAnalytics
@ -19,7 +20,7 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ApplicationScope
class Firebase @Inject constructor(@ForApplication context: Context?, preferences: Preferences) {
class Firebase @Inject constructor(@ForApplication val context: Context, preferences: Preferences) {
private var enabled: Boolean = preferences.isTrackingEnabled
private var analytics: FirebaseAnalytics? = null
@ -39,7 +40,7 @@ class Firebase @Inject constructor(@ForApplication context: Context?, preference
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)
analytics?.logEvent(FirebaseAnalytics.Event.ECOMMERCE_PURCHASE, bundle)
}
fun updateRemoteConfig() {
@ -51,6 +52,19 @@ class Firebase @Inject constructor(@ForApplication context: Context?, preference
}
}
fun logEvent(@StringRes event: Int, vararg p: Pair<Int, Any>) {
val bundle = Bundle()
p.forEach {
val key = context.getString(it.first)
when (it.second::class) {
String::class -> bundle.putString(key, it.second as String)
Boolean::class -> bundle.putBoolean(key, it.second as Boolean)
else -> Timber.e("Unhandled param: $it")
}
}
analytics?.logEvent(context.getString(event), bundle)
}
fun noChurn(): Boolean = remoteConfig?.getBoolean("no_churn") ?: false
init {

@ -1,6 +1,7 @@
package org.tasks.dialogs
import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Bundle
@ -34,6 +35,9 @@ class WhatsNewDialog : InjectingDialogFragment() {
@BindView(R.id.action_button) lateinit var actionButton: MaterialButton
@BindView(R.id.dismiss_button) lateinit var dismissButton: MaterialButton
private var displayedRate = false
private var displayedSubscribe = false
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val view: View = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_whats_new, null)
ButterKnife.bind(this, view)
@ -48,9 +52,11 @@ class WhatsNewDialog : InjectingDialogFragment() {
actionButton.text = getString(R.string.TLA_menu_donate)
actionButton.setOnClickListener { onDonateClick() }
} else if (firebase.noChurn() && !preferences.getBoolean(R.string.p_clicked_rate, false)) {
displayedRate = true
actionButton.text = getString(R.string.rate_tasks)
actionButton.setOnClickListener { onRateClick() }
} else if (firebase.noChurn() && !inventory.hasPro()) {
displayedSubscribe = true
actionText.text = getString(R.string.support_development_subscribe)
actionButton.text = getString(R.string.button_subscribe)
actionButton.setOnClickListener { onSubscribeClick() }
@ -71,11 +77,13 @@ class WhatsNewDialog : InjectingDialogFragment() {
}
private fun onSubscribeClick() {
logClick(true)
dismiss()
startActivity(Intent(context, PurchaseActivity::class.java))
}
private fun onRateClick() {
logClick(true)
preferences.setBoolean(R.string.p_clicked_rate, true)
dismiss()
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.market_url))))
@ -86,8 +94,26 @@ class WhatsNewDialog : InjectingDialogFragment() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://tasks.org/donate")))
}
override fun onCancel(dialog: DialogInterface) {
logClick(false)
super.onCancel(dialog)
}
@OnClick(R.id.dismiss_button)
fun onDismissClick() = dismiss()
fun onDismissClick() {
logClick(false)
dismiss()
}
private fun logClick(click: Boolean) {
firebase.logEvent(
R.string.event_whats_new,
Pair(R.string.param_click, click),
Pair(R.string.param_whats_new_display_rate, displayedRate),
Pair(R.string.param_whats_new_display_subscribe, displayedSubscribe),
Pair(R.string.param_user_pro, inventory.hasPro()),
Pair(R.string.param_user_no_churn, firebase.noChurn()))
}
override fun inject(component: DialogFragmentComponent) = component.inject(this)
}

@ -361,4 +361,11 @@
<string name="p_show_whats_new">show_whats_new</string>
<string name="p_just_updated">just_updated</string>
<string name="p_clicked_rate">clicked_rate</string>
<string name="event_whats_new">whats_new</string>
<string name="param_whats_new_display_rate">display_rate</string>
<string name="param_whats_new_display_subscribe">display_subscribe</string>
<string name="param_user_no_churn">user_no_churn</string>
<string name="param_user_pro">user_pro</string>
<string name="param_click">click</string>
</resources>

Loading…
Cancel
Save