Skip to content

Commit 22f758e

Browse files
committed
fix(fc): properly identify devices/users for MixPanel
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 7e72bff commit 22f758e

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

  • services/flipchat/core/src/main/kotlin/xyz/flipchat/services/user

services/flipchat/core/src/main/kotlin/xyz/flipchat/services/user/UserManager.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import com.getcode.crypt.DerivedKey
55
import com.getcode.ed25519.Ed25519.KeyPair
66
import com.getcode.generator.OrganizerGenerator
77
import com.getcode.model.ID
8+
import com.getcode.model.description
89
import com.getcode.model.uuid
910
import com.getcode.services.manager.MnemonicManager
1011
import com.getcode.solana.organizer.Organizer
1112
import com.getcode.utils.FormatUtils
13+
import com.mixpanel.android.mpmetrics.MixpanelAPI
1214
import kotlinx.coroutines.flow.MutableStateFlow
1315
import kotlinx.coroutines.flow.StateFlow
1416
import kotlinx.coroutines.flow.asStateFlow
@@ -31,6 +33,7 @@ sealed interface AuthState {
3133
class UserManager @Inject constructor(
3234
private val mnemonicManager: MnemonicManager,
3335
private val organizerGenerator: OrganizerGenerator,
36+
private val mixpanelAPI: MixpanelAPI,
3437
) {
3538
private val _state: MutableStateFlow<State> = MutableStateFlow(State())
3639
val state: StateFlow<State>
@@ -130,18 +133,23 @@ class UserManager @Inject constructor(
130133
}
131134

132135
private fun associate() {
133-
if (Bugsnag.isStarted() && !BuildConfig.DEBUG) {
134-
Bugsnag.setUser(userId?.uuid?.toString(), null, displayName)
135-
userFlags?.let { flags ->
136-
Bugsnag.addMetadata(
137-
/* section = */ "userflags",
138-
/* value = */ mapOf(
139-
"isStaff" to flags.isStaff,
140-
"isRegistered" to flags.isRegistered,
141-
"createCost" to FormatUtils.formatWholeRoundDown(flags.createCost.toKinValueDouble())
136+
if (!BuildConfig.DEBUG) {
137+
val distinctId = userId?.uuid?.toString()
138+
if (Bugsnag.isStarted()) {
139+
Bugsnag.setUser(distinctId, null, displayName)
140+
userFlags?.let { flags ->
141+
Bugsnag.addMetadata(
142+
/* section = */ "userflags",
143+
/* value = */ mapOf(
144+
"isStaff" to flags.isStaff,
145+
"isRegistered" to flags.isRegistered,
146+
"createCost" to FormatUtils.formatWholeRoundDown(flags.createCost.toKinValueDouble())
147+
)
142148
)
143-
)
149+
}
144150
}
151+
152+
mixpanelAPI.identify(distinctId)
145153
}
146154
}
147155

0 commit comments

Comments
 (0)