From 48b339075b19b90af68ba1f0e6618e3983c835f9 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 3 Feb 2022 09:57:44 +0000 Subject: [PATCH 1/4] filtering null values from the identify properties - resetting values to null may cause inconsistent cross device tracking --- .../analytics/impl/DefaultVectorAnalytics.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt index 62d360f5f7..31df1fa055 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt @@ -176,7 +176,7 @@ class DefaultVectorAnalytics @Inject constructor( } override fun updateUserProperties(identity: Identity) { - posthog?.identify(REUSE_EXISTING_ID, identity.getProperties().toPostHogProperties(), IGNORED_OPTIONS) + posthog?.identify(REUSE_EXISTING_ID, identity.getProperties()?.toPostHogUserProperties(), IGNORED_OPTIONS) } private fun Map?.toPostHogProperties(): Properties? { @@ -186,4 +186,14 @@ class DefaultVectorAnalytics @Inject constructor( putAll(this@toPostHogProperties) } } + + /** + * We avoid sending nulls as part of the UserProperties as this will reset the values across all devices + * The Identify event has nullable properties to allow for clients to opt in + */ + private fun Map.toPostHogUserProperties(): Properties { + return Properties().apply { + putAll(this@toPostHogUserProperties.filter { it.value != null }) + } + } } From 227c93b014d9f548a23e1f52295dd5fff138b6c0 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 3 Feb 2022 09:59:40 +0000 Subject: [PATCH 2/4] avoiding tracking the use case until account creation, also means we no longer need to reset the tracking value --- .../im/vector/app/features/onboarding/OnboardingViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt index 8097e90206..a4afe36c6c 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt @@ -465,13 +465,11 @@ class OnboardingViewModel @AssistedInject constructor( private fun handleUpdateUseCase(action: OnboardingAction.UpdateUseCase) { setState { copy(useCase = action.useCase) } - analyticsTracker.updateUserProperties(Identity(ftueUseCaseSelection = action.useCase.toTrackingValue())) _viewEvents.post(OnboardingViewEvents.OpenServerSelection) } private fun resetUseCase() { setState { copy(useCase = null) } - analyticsTracker.updateUserProperties(Identity(ftueUseCaseSelection = null)) } private fun handleUpdateServerType(action: OnboardingAction.UpdateServerType) { @@ -754,6 +752,7 @@ class OnboardingViewModel @AssistedInject constructor( private suspend fun onSessionCreated(session: Session) { awaitState().useCase?.let { useCase -> session.vectorStore(applicationContext).setUseCase(useCase) + analyticsTracker.updateUserProperties(Identity(ftueUseCaseSelection = useCase.toTrackingValue())) } activeSessionHolder.setActiveSession(session) From 26beb97f1ea5af56644c6e1887c30e6f010cf03c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 3 Feb 2022 11:34:09 +0000 Subject: [PATCH 3/4] adding changelog entry --- changelog.d/5142.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5142.bugfix diff --git a/changelog.d/5142.bugfix b/changelog.d/5142.bugfix new file mode 100644 index 0000000000..35b2cb8967 --- /dev/null +++ b/changelog.d/5142.bugfix @@ -0,0 +1 @@ +Aligns use case identifying with iOS implementation \ No newline at end of file From 3f3cac0489342ea0fdcd90fe80237bd711bfe77c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Feb 2022 17:33:43 +0000 Subject: [PATCH 4/4] updating changelog to include analytics prefix --- changelog.d/5142.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/5142.bugfix b/changelog.d/5142.bugfix index 35b2cb8967..787a171c3c 100644 --- a/changelog.d/5142.bugfix +++ b/changelog.d/5142.bugfix @@ -1 +1 @@ -Aligns use case identifying with iOS implementation \ No newline at end of file +Analytics: aligns use case identifying with iOS implementation