From 127169f5ffd8569fd65a6e9532cc629ba5d6c6f3 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Thu, 13 Feb 2020 11:16:02 -0800 Subject: [PATCH] For mozilla-mobile#8172: Add a new 'E_Fennec_To_Fenix_Migrated' Leanplum event This new event will be sent when the user has successfully migrated from Fennec to Fenix. This event will only be sent to Leanplum and not to the other telemetry services like Glean or Adjust. Co-authored-by: ValentinTimisica --- .../components/metrics/GleanMetricsService.kt | 1 + .../metrics/LeanplumMetricsService.kt | 1 + .../fenix/components/metrics/Metrics.kt | 1 + .../migration/MigrationTelemetryListener.kt | 32 +++++++++++++++++++ .../fenix/MigratingFenixApplication.kt | 8 +++++ docs/mma.md | 5 +++ 6 files changed, 48 insertions(+) create mode 100644 app/src/main/java/org/mozilla/fenix/migration/MigrationTelemetryListener.kt diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index b103eb0f6..6cbc8ae69 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -494,6 +494,7 @@ private val Event.wrapper: EventWrapper<*>? is Event.InteractWithSearchURLArea -> null is Event.ClearedPrivateData -> null is Event.DismissedOnboarding -> null + is Event.FennecToFenixMigrated -> null } class GleanMetricsService(private val context: Context) : MetricsService { diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt index 3c1de96d4..8744325c8 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt @@ -30,6 +30,7 @@ private val Event.name: String? is Event.SyncAuthSignOut -> "E_Sign_Out_FxA" is Event.ClearedPrivateData -> "E_Cleared_Private_Data" is Event.DismissedOnboarding -> "E_Dismissed_Onboarding" + is Event.FennecToFenixMigrated -> "E_Fennec_To_Fenix_Migrated" // Do not track other events in Leanplum else -> "" diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 8a40fbd26..4e0059021 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -149,6 +149,7 @@ sealed class Event { object RightsTapped : Event() object LicensingTapped : Event() object LibrariesThatWeUseTapped : Event() + object FennecToFenixMigrated : Event() // Interaction events with extras diff --git a/app/src/main/java/org/mozilla/fenix/migration/MigrationTelemetryListener.kt b/app/src/main/java/org/mozilla/fenix/migration/MigrationTelemetryListener.kt new file mode 100644 index 000000000..ffd148426 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/migration/MigrationTelemetryListener.kt @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.collect +import mozilla.components.lib.state.ext.flowScoped +import mozilla.components.support.base.log.logger.Logger +import mozilla.components.support.migration.state.MigrationProgress +import mozilla.components.support.migration.state.MigrationStore +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.MetricController + +class MigrationTelemetryListener( + private val metrics: MetricController, + private val store: MigrationStore +) { + @UseExperimental(ExperimentalCoroutinesApi::class) + fun start() { + // Observe for migration completed. + store.flowScoped { flow -> + flow.collect { state -> + Logger("MigrationTelemetryListener").debug("Migration state: ${state.progress}") + if (state.progress == MigrationProgress.COMPLETED) { + metrics.track(Event.FennecToFenixMigrated) + } + } + } + } +} diff --git a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt index 5439fddb6..8ff88f9dd 100644 --- a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt +++ b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt @@ -42,6 +42,13 @@ class MigratingFenixApplication : FenixApplication() { ) } + val migrationTelemetryListener by lazy { + MigrationTelemetryListener( + components.analytics.metrics, + components.migrationStore + ) + } + override fun setupInMainProcessOnly() { // These migrations need to run before regular initialization happens. migrateBlocking() @@ -55,6 +62,7 @@ class MigratingFenixApplication : FenixApplication() { // The rest of the migrations can happen now. migrationPushSubscriber.start() + migrationTelemetryListener.start() migrator.startMigrationIfNeeded(components.migrationStore, MigrationService::class.java) } diff --git a/docs/mma.md b/docs/mma.md index c3729b55c..26f33e1c6 100644 --- a/docs/mma.md +++ b/docs/mma.md @@ -226,6 +226,11 @@ Here is the list of current Events sent, which can be found here in the code bas The user finished onboarding. Could be triggered by pressing "start browsing," opening settings, or invoking a search. #3459 + + `E_Fennec_To_Fenix_Migrated` + The user has just migrated from Fennec to Fenix. + #8208 + Deep links