Skip to content

Commit b969f78

Browse files
authored
Merge pull request #430 from code-payments/chore/add-bg-swap-analytics
chore(api): add analytics around background swaps
2 parents c82aedc + 12f35f0 commit b969f78

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

api/src/main/java/com/getcode/analytics/AnalyticsManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ class AnalyticsManager @Inject constructor(
238238
)
239239
}
240240

241+
override fun backgroundSwapInitiated() {
242+
track(Name.BackgroundSwap)
243+
}
244+
241245
private fun track(event: Name, vararg properties: Pair<Property, String>) {
242246
if (BuildConfig.DEBUG) {
243247
Timber.d("debug track $event, ${properties.map { "${it.first.name}, ${it.second}" }}")
@@ -276,6 +280,7 @@ class AnalyticsManager @Inject constructor(
276280
UpgradePrivacy("Upgrade Privacy"),
277281
ClaimGetFreeKin("Claim Get Free Kin"),
278282
PrivacyMigration("Privacy Migration"),
283+
BackgroundSwap("Background Swap Initiated"),
279284

280285
// Errors
281286
ErrorRequest("Error Request"),

api/src/main/java/com/getcode/analytics/AnalyticsService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ interface AnalyticsService {
4444
fun onBillReceived()
4545

4646
fun tipCardShown(username: String)
47+
48+
fun backgroundSwapInitiated()
4749
}
4850

4951
class AnalyticsServiceNull : AnalyticsService {
@@ -85,4 +87,5 @@ class AnalyticsServiceNull : AnalyticsService {
8587
override fun upgradePrivacy(successful: Boolean, intentId: PublicKey, actionCount: Int) = Unit
8688
override fun onBillReceived() = Unit
8789
override fun tipCardShown(username: String) = Unit
90+
override fun backgroundSwapInitiated() = Unit
8891
}

app/src/main/java/com/getcode/notifications/CodePushMessagingService.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.os.Build
99
import androidx.core.app.NotificationCompat
1010
import androidx.core.app.Person
1111
import com.getcode.R
12+
import com.getcode.analytics.AnalyticsService
1213
import com.getcode.manager.AuthManager
1314
import com.getcode.manager.SessionManager
1415
import com.getcode.model.notifications.NotificationType
@@ -42,6 +43,9 @@ import javax.inject.Inject
4243
class CodePushMessagingService : FirebaseMessagingService(),
4344
CoroutineScope by CoroutineScope(Dispatchers.IO) {
4445

46+
@Inject
47+
lateinit var analyticsService: AnalyticsService
48+
4549
@Inject
4650
lateinit var pushRepository: PushRepository
4751

@@ -102,12 +106,16 @@ class CodePushMessagingService : FirebaseMessagingService(),
102106
launch { historyController.fetchChats() }
103107
launch { balanceController.fetchBalanceSuspend() }
104108
}
109+
105110
NotificationType.ExecuteSwap -> {
106-
updateOrganizerAndSwap()
111+
analyticsService.backgroundSwapInitiated()
112+
updateOrganizerAndSwap()
107113
}
114+
108115
NotificationType.Twitter -> {
109116
launch { tipController.checkForConnection() }
110117
}
118+
111119
NotificationType.Unknown -> Unit
112120
}
113121
} else {
@@ -164,7 +172,7 @@ class CodePushMessagingService : FirebaseMessagingService(),
164172
person
165173
)
166174

167-
val style = notificationManager.getActiveNotification(title.hashCode())?.let {
175+
val style = notificationManager.getActiveNotification(title.hashCode())?.let {
168176
NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(it)
169177
} ?: NotificationCompat.MessagingStyle(person)
170178

@@ -199,7 +207,6 @@ class CodePushMessagingService : FirebaseMessagingService(),
199207
}
200208

201209

202-
203210
private fun NotificationManager.getActiveNotification(notificationId: Int): Notification? {
204211
val barNotifications = getActiveNotifications()
205212
for (notification in barNotifications) {

0 commit comments

Comments
 (0)