From 4659ac0c5cf614f589bf9beef54869edf63d2120 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 28 Nov 2024 17:55:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20(Analytics):=20Improve=20logEven?= =?UTF-8?q?t=20App/OS=20update=20alert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Views/MainView/MainView.swift | 8 +-- .../Analytics/AnalyticsManager+App.swift | 52 +++++++++---------- .../Sources/Analytics/AnalyticsManager.swift | 20 +++---- 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/Apps/LekaApp/Sources/Views/MainView/MainView.swift b/Apps/LekaApp/Sources/Views/MainView/MainView.swift index e72879cd6..67d42dc0b 100644 --- a/Apps/LekaApp/Sources/Views/MainView/MainView.swift +++ b/Apps/LekaApp/Sources/Views/MainView/MainView.swift @@ -127,13 +127,13 @@ struct MainView: View { title: Text(l10n.MainView.AppUpdateAlert.title), message: Text(l10n.MainView.AppUpdateAlert.message), primaryButton: .default(Text(l10n.MainView.AppUpdateAlert.action), action: { - AnalyticsManager.logEventAppUpdateOpenAppStore() + AnalyticsManager.logEventAppUpdateAlertResponse(.openAppStore) if let url = URL(string: "https://apps.apple.com/app/leka/id6446940339") { UIApplication.shared.open(url) } }), secondaryButton: .cancel(Text(l10n.MainView.AppUpdateAlert.reminder)) { - AnalyticsManager.logEventAppUpdateRemindLater() + AnalyticsManager.logEventAppUpdateAlertResponse(.remindLater) } ) } @@ -142,13 +142,13 @@ struct MainView: View { title: Text(l10n.MainView.OSUpdateAlert.title), message: Text(l10n.MainView.OSUpdateAlert.message), primaryButton: .default(Text(l10n.MainView.OSUpdateAlert.action), action: { - AnalyticsManager.logEventOSUpdateOpenSettings() + AnalyticsManager.logEventOSUpdateAlertResponse(.openSettings) if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) } }), secondaryButton: .cancel(Text(l10n.MainView.OSUpdateAlert.reminder)) { - AnalyticsManager.logEventOSUpdateRemindLater() + AnalyticsManager.logEventOSUpdateAlertResponse(.remindLater) } ) } diff --git a/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift b/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift index 9928bc46b..07e094fa8 100644 --- a/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift +++ b/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift @@ -5,43 +5,43 @@ import FirebaseAnalytics public extension AnalyticsManager { - // TODO: (@ladislas) add real versions - static func logEventAppUpdateRemindLater(currentVersion: String = "(lk_not_set)", newVersion: String = "(lk_not_set)", parameters: [String: Any] = [:]) { - let params: [String: Any] = [ - "current_version": currentVersion, - "new_version": newVersion, - ].merging(parameters) { _, new in new } - - logEvent(.appUpdateRemindLater, parameters: params) + enum AppUpdateAlertResponseAction: String { + case remindLater = "remind_later" + case openAppStore = "open_app_store" } - // TODO: (@ladislas) add real versions - static func logEventAppUpdateOpenAppStore(currentVersion: String = "(lk_not_set)", newVersion: String = "(lk_not_set)", parameters: [String: Any] = [:]) { + static func logEventAppUpdateAlertResponse( + _ action: AppUpdateAlertResponseAction, + currentVersion _: String = "", // TODO: (@ladislas) add current/new versions + newVersion _: String = "", + parameters: [String: Any] = [:] + ) { let params: [String: Any] = [ - "current_version": currentVersion, - "new_version": newVersion, + "lk_app_version_current": NSNull(), + "lk_app_version_update": NSNull(), + "lk_response_action": action.rawValue, ].merging(parameters) { _, new in new } - logEvent(.appUpdateOpenAppStore, parameters: params) + logEvent(.appUpdateAlertResponse, parameters: params) } - // TODO: (@ladislas) add real versions - static func logEventOSUpdateRemindLater(currentVersion: String = "(lk_not_set)", newVersion: String = "(lk_not_set)", parameters: [String: Any] = [:]) { - let params: [String: Any] = [ - "current_version": currentVersion, - "new_version": newVersion, - ].merging(parameters) { _, new in new } - - logEvent(.osUpdateRemindLater, parameters: params) + enum OSUpdateAlertResponseAction: String { + case remindLater = "remind_later" + case openSettings = "open_settings" } - // TODO: (@ladislas) add real versions - static func logEventOSUpdateOpenSettings(currentVersion: String = "(lk_not_set)", newVersion: String = "(lk_not_set)", parameters: [String: Any] = [:]) { + static func logEventOSUpdateAlertResponse( + _ action: OSUpdateAlertResponseAction, + currentVersion _: String = "", // TODO: (@ladislas) add current/new versions + newVersion _: String = "", + parameters: [String: Any] = [:] + ) { let params: [String: Any] = [ - "current_version": currentVersion, - "new_version": newVersion, + "lk_os_version_current": NSNull(), + "lk_os_version_update": NSNull(), + "lk_response_action": action.rawValue, ].merging(parameters) { _, new in new } - logEvent(.osUpdateOpenSettings, parameters: params) + logEvent(.osUpdateAlertResponse, parameters: params) } } diff --git a/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift b/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift index 3d9e6fe87..fbac48f79 100644 --- a/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift +++ b/Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift @@ -23,11 +23,8 @@ public class AnalyticsManager { case activityStart case activityEnd - case appUpdateRemindLater - case appUpdateOpenAppStore - - case osUpdateRemindLater - case osUpdateOpenSettings + case appUpdateAlertResponse + case osUpdateAlertResponse case login case logout @@ -55,15 +52,10 @@ public class AnalyticsManager { case .activityEnd: "activity_end" - case .appUpdateRemindLater: - "app_update_remind_later" - case .appUpdateOpenAppStore: - "app_update_open_app_store" - - case .osUpdateRemindLater: - "os_update_remind_later" - case .osUpdateOpenSettings: - "os_update_open_settings" + case .appUpdateAlertResponse: + "app_update_alert_response" + case .osUpdateAlertResponse: + "os_update_alert_response" case .login: AnalyticsEventLogin // ? "login"