Skip to content

chore(api): add analytics around background swaps #430

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 3, 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
5 changes: 5 additions & 0 deletions api/src/main/java/com/getcode/analytics/AnalyticsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class AnalyticsManager @Inject constructor(
)
}

override fun backgroundSwapInitiated() {
track(Name.BackgroundSwap)
}

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 @@ -276,6 +280,7 @@ class AnalyticsManager @Inject constructor(
UpgradePrivacy("Upgrade Privacy"),
ClaimGetFreeKin("Claim Get Free Kin"),
PrivacyMigration("Privacy Migration"),
BackgroundSwap("Background Swap Initiated"),

// Errors
ErrorRequest("Error Request"),
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/com/getcode/analytics/AnalyticsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ interface AnalyticsService {
fun onBillReceived()

fun tipCardShown(username: String)

fun backgroundSwapInitiated()
}

class AnalyticsServiceNull : AnalyticsService {
Expand Down Expand Up @@ -85,4 +87,5 @@ class AnalyticsServiceNull : AnalyticsService {
override fun upgradePrivacy(successful: Boolean, intentId: PublicKey, actionCount: Int) = Unit
override fun onBillReceived() = Unit
override fun tipCardShown(username: String) = Unit
override fun backgroundSwapInitiated() = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import com.getcode.R
import com.getcode.analytics.AnalyticsService
import com.getcode.manager.AuthManager
import com.getcode.manager.SessionManager
import com.getcode.model.notifications.NotificationType
Expand Down Expand Up @@ -42,6 +43,9 @@ import javax.inject.Inject
class CodePushMessagingService : FirebaseMessagingService(),
CoroutineScope by CoroutineScope(Dispatchers.IO) {

@Inject
lateinit var analyticsService: AnalyticsService

@Inject
lateinit var pushRepository: PushRepository

Expand Down Expand Up @@ -102,12 +106,16 @@ class CodePushMessagingService : FirebaseMessagingService(),
launch { historyController.fetchChats() }
launch { balanceController.fetchBalanceSuspend() }
}

NotificationType.ExecuteSwap -> {
updateOrganizerAndSwap()
analyticsService.backgroundSwapInitiated()
updateOrganizerAndSwap()
}

NotificationType.Twitter -> {
launch { tipController.checkForConnection() }
}

NotificationType.Unknown -> Unit
}
} else {
Expand Down Expand Up @@ -164,7 +172,7 @@ class CodePushMessagingService : FirebaseMessagingService(),
person
)

val style = notificationManager.getActiveNotification(title.hashCode())?.let {
val style = notificationManager.getActiveNotification(title.hashCode())?.let {
NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(it)
} ?: NotificationCompat.MessagingStyle(person)

Expand Down Expand Up @@ -199,7 +207,6 @@ class CodePushMessagingService : FirebaseMessagingService(),
}



private fun NotificationManager.getActiveNotification(notificationId: Int): Notification? {
val barNotifications = getActiveNotifications()
for (notification in barNotifications) {
Expand Down
Loading