Skip to content

chore: add analytics around app settings toggled #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion api/src/main/java/com/getcode/analytics/AnalyticsManager.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.getcode.analytics

import com.getcode.api.BuildConfig
import com.getcode.model.AppSetting
import com.getcode.model.CurrencyCode
import com.getcode.model.Kin
import com.getcode.model.KinAmount
import com.getcode.model.PrefsBool
import com.getcode.solana.keys.PublicKey
import com.getcode.solana.keys.base58
import com.google.firebase.ktx.Firebase
Expand Down Expand Up @@ -92,7 +94,11 @@ class AnalyticsManager @Inject constructor(
)
}

override fun billHidden(kin: Kin, currencyCode: CurrencyCode, animation: BillPresentationStyle) {
override fun billHidden(
kin: Kin,
currencyCode: CurrencyCode,
animation: BillPresentationStyle
) {
track(
Name.Bill,
Pair(Property.State, StringValue.Hidden.value),
Expand Down Expand Up @@ -247,6 +253,17 @@ class AnalyticsManager @Inject constructor(
track(Name.BackgroundSwap)
}

override fun appSettingToggled(setting: AppSetting, value: Boolean) {
val name = when (setting) {
PrefsBool.CAMERA_START_BY_DEFAULT -> Name.AutoStartCamera
}

track(
name,
Property.State to if (value) StringValue.Yes.value else StringValue.No.value,
)
}

private fun track(event: Name, vararg properties: Pair<Property, String>) {
if (BuildConfig.DEBUG) {
Timber.d("debug track $event, ${properties.map { "${it.first.name}, ${it.second}" }}")
Expand Down Expand Up @@ -292,6 +309,9 @@ class AnalyticsManager @Inject constructor(
ErrorRequest("Error Request"),

Recompute("Recompute"),

// App Settings
AutoStartCamera("Auto Start Camera")
}

enum class Property(val value: String) {
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/com/getcode/analytics/AnalyticsService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.getcode.analytics

import com.getcode.model.AppSetting
import com.getcode.model.CurrencyCode
import com.getcode.model.Kin
import com.getcode.model.KinAmount
Expand Down Expand Up @@ -47,6 +48,8 @@ interface AnalyticsService {

fun backgroundSwapInitiated()
fun unintentionalLogout()

fun appSettingToggled(setting: AppSetting, value: Boolean)
}

class AnalyticsServiceNull : AnalyticsService {
Expand Down Expand Up @@ -90,4 +93,5 @@ class AnalyticsServiceNull : AnalyticsService {
override fun tipCardShown(username: String) = Unit
override fun backgroundSwapInitiated() = Unit
override fun unintentionalLogout() = Unit
override fun appSettingToggled(setting: AppSetting, value: Boolean) = Unit
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.getcode.network.repository

import com.getcode.analytics.AnalyticsService
import com.getcode.model.AppSetting
import com.getcode.model.PrefsBool
import kotlinx.coroutines.flow.Flow
Expand All @@ -17,6 +18,7 @@ data class AppSettings(
}
class AppSettingsRepository @Inject constructor(
private val prefRepository: PrefRepository,
private val analytics: AnalyticsService,
) {

fun observe(): Flow<AppSettings> = AppSettings.Defaults.let { defaults ->
Expand All @@ -34,6 +36,7 @@ class AppSettingsRepository @Inject constructor(
}

fun update(setting: AppSetting, value: Boolean) {
analytics.appSettingToggled(setting, value)
when (setting) {
PrefsBool.CAMERA_START_BY_DEFAULT -> {
prefRepository.set(PrefsBool.CAMERA_START_BY_DEFAULT, value)
Expand Down
Loading