From a6df939643937395eb1a77d7ccebf807932b9e14 Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:46:55 +0100 Subject: [PATCH 01/11] Add pref key --- firefox-ios/Shared/Prefs.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firefox-ios/Shared/Prefs.swift b/firefox-ios/Shared/Prefs.swift index 0ed65d770189..4ed1538e5266 100644 --- a/firefox-ios/Shared/Prefs.swift +++ b/firefox-ios/Shared/Prefs.swift @@ -196,6 +196,10 @@ public struct PrefsKeys { // Represents whether or not the user has seen the photon main menu once, at least. public static let PhotonMainMenuShown = "PhotonMainMenuShown" + + public struct Usage { + public static let profileId = "profileId" + } } public protocol Prefs { From 4c3a0e2abc70995f2a2461f88c7114f6f1c23add Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:47:32 +0100 Subject: [PATCH 02/11] Add usage metric --- firefox-ios/Client/metrics.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/firefox-ios/Client/metrics.yaml b/firefox-ios/Client/metrics.yaml index 984142b38e04..6217e3322bb5 100755 --- a/firefox-ios/Client/metrics.yaml +++ b/firefox-ios/Client/metrics.yaml @@ -709,6 +709,27 @@ app: - fx-ios-data-stewards@mozilla.com expires: "2025-01-01" +# DAU reporting +usage: + profile_id: + type: uuid + lifetime: user + description: | + A UUID uniquely identifying the profile, + not shared with other telemetry data. + bugs: + - https://github.com/mozilla-mobile/firefox-ios/pull/ + data_reviews: + - https://github.com/mozilla-mobile/firefox-ios/pull/ + data_sensitivity: + - technical + - highly_sensitive + notification_emails: + - fx-ios-data-stewards@mozilla.com + expires: never + send_in_pings: + - dau-reporting + # Downloads downloads: download_now_button_tapped: From bbf9033ffa973c5057b01fb859679af97be79daa Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:47:48 +0100 Subject: [PATCH 03/11] Set or generate profile id --- firefox-ios/Client/Telemetry/TelemetryWrapper.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/firefox-ios/Client/Telemetry/TelemetryWrapper.swift b/firefox-ios/Client/Telemetry/TelemetryWrapper.swift index fd0f9efd877d..22d29c55b39a 100644 --- a/firefox-ios/Client/Telemetry/TelemetryWrapper.swift +++ b/firefox-ios/Client/Telemetry/TelemetryWrapper.swift @@ -104,6 +104,14 @@ class TelemetryWrapper: TelemetryWrapperProtocol, FeatureFlaggable { GleanMetrics.LegacyIds.clientId.set(uuid) } + // Set or generate profile id used for usage reporting + if let uuidString = profile.prefs.stringForKey(PrefsKeys.Usage.profileId), let uuid = UUID(uuidString: uuidString) { + GleanMetrics.Usage.profileId.set(uuid) + } else { + let uuid = GleanMetrics.Usage.profileId.generateAndSet() + profile.prefs.setString(uuid.uuidString, forKey: PrefsKeys.Usage.profileId) + } + glean.registerPings(GleanMetrics.Pings.shared) // Initialize Glean telemetry From 33f1fde359cc234bb88793f3ffc58149e5c5b9da Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:48:12 +0100 Subject: [PATCH 04/11] Delete profile id when user turns off reporting --- .../Main/Support/SendAnonymousUsageDataSetting.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift b/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift index ddeddfda4986..e8e9103af8f9 100644 --- a/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift +++ b/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift @@ -4,6 +4,7 @@ import Common import Foundation +import Glean import Shared class SendAnonymousUsageDataSetting: BoolSetting { @@ -54,6 +55,11 @@ class SendAnonymousUsageDataSetting: BoolSetting { self.settingDidChange = { [weak self] value in // AdjustHelper.setEnabled($0) DefaultGleanWrapper.shared.setUpload(isEnabled: value) + + if !value { + self?.prefs?.removeObjectForKey(PrefsKeys.Usage.profileId) + } + Experiments.setTelemetrySetting(value) self?.shouldSendUsageData?(value) } From b3832ef217401383bbded1ba4a54109779cdeb5e Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:58:31 +0100 Subject: [PATCH 05/11] Update firefox-ios/Client/metrics.yaml Co-authored-by: Jan-Erik Rediger --- firefox-ios/Client/metrics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firefox-ios/Client/metrics.yaml b/firefox-ios/Client/metrics.yaml index bbc2933a8806..5dee843ff921 100755 --- a/firefox-ios/Client/metrics.yaml +++ b/firefox-ios/Client/metrics.yaml @@ -728,7 +728,7 @@ usage: - fx-ios-data-stewards@mozilla.com expires: never send_in_pings: - - dau-reporting + - usage-reporting # Downloads downloads: From da4e2f2b34d559810836dc14ae19b747cc044fdb Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:58:45 +0100 Subject: [PATCH 06/11] Update firefox-ios/Client/metrics.yaml Co-authored-by: Jan-Erik Rediger --- firefox-ios/Client/metrics.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/firefox-ios/Client/metrics.yaml b/firefox-ios/Client/metrics.yaml index 5dee843ff921..919ee0a9cbca 100755 --- a/firefox-ios/Client/metrics.yaml +++ b/firefox-ios/Client/metrics.yaml @@ -726,6 +726,7 @@ usage: - highly_sensitive notification_emails: - fx-ios-data-stewards@mozilla.com + - glean-team@mozilla.com expires: never send_in_pings: - usage-reporting From 442ce32a25dee4366997859c9521a0a344173c01 Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:59:17 +0100 Subject: [PATCH 07/11] Update firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift Co-authored-by: Jan-Erik Rediger --- .../Settings/Main/Support/SendAnonymousUsageDataSetting.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift b/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift index e8e9103af8f9..85b702679165 100644 --- a/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift +++ b/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift @@ -58,6 +58,7 @@ class SendAnonymousUsageDataSetting: BoolSetting { if !value { self?.prefs?.removeObjectForKey(PrefsKeys.Usage.profileId) + GleanMetrics.Usage.profileId.set(UUID(uuidString: "beefbeef-beef-beef-beef-beeefbeefbee")) } Experiments.setTelemetrySetting(value) From ec45364eacbb9aa568a2eae179d114cf5d12724b Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:03:52 +0100 Subject: [PATCH 08/11] Update metrics --- firefox-ios/Client/metrics.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firefox-ios/Client/metrics.yaml b/firefox-ios/Client/metrics.yaml index 919ee0a9cbca..75dda94eedc0 100755 --- a/firefox-ios/Client/metrics.yaml +++ b/firefox-ios/Client/metrics.yaml @@ -709,7 +709,7 @@ app: - fx-ios-data-stewards@mozilla.com expires: "2025-01-01" -# DAU reporting +# Usage reporting usage: profile_id: type: uuid @@ -718,9 +718,9 @@ usage: A UUID uniquely identifying the profile, not shared with other telemetry data. bugs: - - https://github.com/mozilla-mobile/firefox-ios/pull/ + - https://github.com/mozilla-mobile/firefox-ios/pull/23254 data_reviews: - - https://github.com/mozilla-mobile/firefox-ios/pull/ + - https://github.com/mozilla-mobile/firefox-ios/pull/23254 data_sensitivity: - technical - highly_sensitive From 97daa50ecc0e11e28cbe9865c7be8a921ed787c6 Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:04:00 +0100 Subject: [PATCH 09/11] Fix build error --- .../Main/Support/SendAnonymousUsageDataSetting.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift b/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift index 85b702679165..10da4ad7db1a 100644 --- a/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift +++ b/firefox-ios/Client/Frontend/Settings/Main/Support/SendAnonymousUsageDataSetting.swift @@ -58,7 +58,11 @@ class SendAnonymousUsageDataSetting: BoolSetting { if !value { self?.prefs?.removeObjectForKey(PrefsKeys.Usage.profileId) - GleanMetrics.Usage.profileId.set(UUID(uuidString: "beefbeef-beef-beef-beef-beeefbeefbee")) + + // set dummy uuid to make sure the previous one is deleted + if let uuid = UUID(uuidString: "beefbeef-beef-beef-beef-beeefbeefbee") { + GleanMetrics.Usage.profileId.set(uuid) + } } Experiments.setTelemetrySetting(value) From 56da59e1194be1825df2f3f398e14fc2269dfcd5 Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:10:42 +0100 Subject: [PATCH 10/11] Addressing PR comments --- .../Client/Telemetry/TelemetryWrapper.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/firefox-ios/Client/Telemetry/TelemetryWrapper.swift b/firefox-ios/Client/Telemetry/TelemetryWrapper.swift index 963cb92f733b..585543857e36 100644 --- a/firefox-ios/Client/Telemetry/TelemetryWrapper.swift +++ b/firefox-ios/Client/Telemetry/TelemetryWrapper.swift @@ -100,16 +100,23 @@ class TelemetryWrapper: TelemetryWrapperProtocol, FeatureFlaggable { GleanMetrics.Search.defaultEngine.set(defaultEngine?.engineID ?? "unavailable") // Get the legacy telemetry ID and record it in Glean for the deletion-request ping - if let uuidString = UserDefaults.standard.string(forKey: "telemetry-key-prefix-clientId"), let uuid = UUID(uuidString: uuidString) { + if let uuidString = UserDefaults.standard.string(forKey: "telemetry-key-prefix-clientId"), + let uuid = UUID(uuidString: uuidString) { GleanMetrics.LegacyIds.clientId.set(uuid) } // Set or generate profile id used for usage reporting - if let uuidString = profile.prefs.stringForKey(PrefsKeys.Usage.profileId), let uuid = UUID(uuidString: uuidString) { + if profile.prefs.boolForKey(AppConstants.prefSendUsageData) ?? true { + if let uuidString = profile.prefs.stringForKey(PrefsKeys.Usage.profileId), + let uuid = UUID(uuidString: uuidString) { + GleanMetrics.Usage.profileId.set(uuid) + } else { + let uuid = GleanMetrics.Usage.profileId.generateAndSet() + profile.prefs.setString(uuid.uuidString, forKey: PrefsKeys.Usage.profileId) + } + } else if let uuid = UUID(uuidString: "beefbeef-beef-beef-beef-beeefbeefbee") { + // set dummy uuid to make sure the previous one is deleted GleanMetrics.Usage.profileId.set(uuid) - } else { - let uuid = GleanMetrics.Usage.profileId.generateAndSet() - profile.prefs.setString(uuid.uuidString, forKey: PrefsKeys.Usage.profileId) } glean.registerPings(GleanMetrics.Pings.shared) From 5ab7ffcb809e7d7ab21e84b7a60e69ad77371bdc Mon Sep 17 00:00:00 2001 From: Winnie Teichmann <4530+thatswinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:07:57 +0100 Subject: [PATCH 11/11] Update firefox-ios/Client/Telemetry/TelemetryWrapper.swift Co-authored-by: Jan-Erik Rediger --- firefox-ios/Client/Telemetry/TelemetryWrapper.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firefox-ios/Client/Telemetry/TelemetryWrapper.swift b/firefox-ios/Client/Telemetry/TelemetryWrapper.swift index 585543857e36..f82fe184a3f6 100644 --- a/firefox-ios/Client/Telemetry/TelemetryWrapper.swift +++ b/firefox-ios/Client/Telemetry/TelemetryWrapper.swift @@ -106,7 +106,7 @@ class TelemetryWrapper: TelemetryWrapperProtocol, FeatureFlaggable { } // Set or generate profile id used for usage reporting - if profile.prefs.boolForKey(AppConstants.prefSendUsageData) ?? true { + if sendUsageData { if let uuidString = profile.prefs.stringForKey(PrefsKeys.Usage.profileId), let uuid = UUID(uuidString: uuidString) { GleanMetrics.Usage.profileId.set(uuid)