Skip to content

Commit

Permalink
Merge pull request #3155 from CruGlobal/accountTypeAnalytics
Browse files Browse the repository at this point in the history
GT-2151 record the authenticated account type as a firebase user property
  • Loading branch information
frett authored Oct 16, 2023
2 parents 28cc655 + 7949af8 commit fd9f273
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ facebook = "16.2.0"
facebook-flipper = "0.226.0"
firebase-crashlytics = "18.4.3"
firebase-perf = "20.4.1"
godtoolsShared = "0.9.1"
godtoolsShared = "0.9.2-SNAPSHOT"
google-auto-value = "1.10.4"
gtoSupport = "4.2.0-SNAPSHOT"
kotlin = "1.9.10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class GodToolsAccountManager @VisibleForTesting internal constructor(
.flatMapLatest { it?.isAuthenticatedFlow() ?: flowOf(false) }
.shareIn(coroutineScope, SharingStarted.WhileSubscribed(), replay = 1)
.distinctUntilChanged()
val authenticatedAccountTypeFlow = activeProviderFlow
.map { it?.type }
.shareIn(coroutineScope, SharingStarted.WhileSubscribed(), replay = 1)
.distinctUntilChanged()
val userIdFlow = activeProviderFlow
.flatMapLatest { it?.userIdFlow() ?: flowOf(null) }
.shareIn(coroutineScope, SharingStarted.WhileSubscribed(), replay = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.cru.godtools.account.AccountType
import org.cru.godtools.account.GodToolsAccountManager
import org.cru.godtools.analytics.BuildConfig
import org.cru.godtools.analytics.model.AnalyticsActionEvent
import org.cru.godtools.analytics.model.AnalyticsBaseEvent
import org.cru.godtools.analytics.model.AnalyticsScreenEvent
import org.cru.godtools.analytics.model.AnalyticsSystem
import org.cru.godtools.shared.analytics.AnalyticsUserProperties
import org.cru.godtools.user.data.UserManager
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
Expand All @@ -33,7 +35,6 @@ private const val VALUE_APP_TYPE_INSTANT = "instant"
private const val VALUE_APP_TYPE_INSTALLED = "installed"

private const val USER_PROP_DEBUG = "debug"
private const val USER_PROP_LOGGED_IN_STATUS = "cru_loggedinstatus"
private const val USER_PROP_SSO_GUID = "cru_ssoguid"
private const val USER_PROP_GR_MASTER_PERSON_ID = "cru_grmasterpersonid"

Expand All @@ -49,7 +50,7 @@ class FirebaseAnalyticsService @VisibleForTesting internal constructor(
eventBus: EventBus,
userManager: UserManager,
private val firebase: FirebaseAnalytics,
coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Default)
coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Default),
) {
@Inject
@MainThread
Expand Down Expand Up @@ -108,8 +109,18 @@ class FirebaseAnalyticsService @VisibleForTesting internal constructor(
}
.launchIn(coroutineScope)

accountManager.isAuthenticatedFlow
.onEach { firebase.setUserProperty(USER_PROP_LOGGED_IN_STATUS, "$it") }
accountManager.authenticatedAccountTypeFlow
.onEach {
firebase.setUserProperty(AnalyticsUserProperties.LOGGED_IN_STATUS, "${it != null}")
firebase.setUserProperty(
AnalyticsUserProperties.LOGIN_PROVIDER,
when (it) {
AccountType.FACEBOOK -> AnalyticsUserProperties.LOGIN_PROVIDER_FACEBOOK
AccountType.GOOGLE -> AnalyticsUserProperties.LOGIN_PROVIDER_GOOGLE
null -> null
}
)
}
.launchIn(coroutineScope)

firebase.setUserProperty(USER_PROP_APP_NAME, VALUE_APP_NAME_GODTOOLS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FirebaseAnalyticsServiceTest {
private val userFlow = MutableSharedFlow<User?>()

private val accountManager: GodToolsAccountManager = mockk {
every { isAuthenticatedFlow } returns flowOf(false)
every { authenticatedAccountTypeFlow } returns flowOf(null)
}
private val eventBus: EventBus = mockk(relaxUnitFun = true)
private val firebase: FirebaseAnalytics = mockk(relaxUnitFun = true)
Expand Down

0 comments on commit fd9f273

Please sign in to comment.