Skip to content

Commit

Permalink
📈 (Analytics): Improve logEvent App/OS update alert
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 28, 2024
1 parent c3845a4 commit 4659ac0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
8 changes: 4 additions & 4 deletions Apps/LekaApp/Sources/Views/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
Expand All @@ -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)
}
)
}
Expand Down
52 changes: 26 additions & 26 deletions Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 15 in Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) add current/new ve...) (todo)
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

Check warning on line 35 in Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager+App.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) add current/new ve...) (todo)
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)
}
}
20 changes: 6 additions & 14 deletions Modules/AnalyticsKit/Sources/Analytics/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4659ac0

Please sign in to comment.