Skip to content

Commit

Permalink
Remove some managed events
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed May 7, 2024
1 parent bb969b1 commit 488b9bd
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions Sources/Confidence/ConfidenceAppLifecycleProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ public class ConfidenceAppLifecycleProducer: ConfidenceEventProducer, Confidence
private var appNotifications: [NSNotification.Name] = [
UIApplication.didEnterBackgroundNotification,
UIApplication.willEnterForegroundNotification,
UIApplication.didFinishLaunchingNotification,
UIApplication.didBecomeActiveNotification,
UIApplication.willResignActiveNotification,
UIApplication.didReceiveMemoryWarningNotification,
UIApplication.willTerminateNotification,
UIApplication.significantTimeChangeNotification,
UIApplication.backgroundRefreshStatusDidChangeNotification
UIApplication.didFinishLaunchingNotification
]

private static var versionNameKey = "CONFIDENCE_VERSION_NAME_KEY"
Expand Down Expand Up @@ -57,26 +51,18 @@ public class ConfidenceAppLifecycleProducer: ConfidenceEventProducer, Confidence
.eraseToAnyPublisher()
}

private func track(eventName: String, sourceApp: String = "", url: String = "") {
private func track(eventName: String) {
let previousBuild: String? = UserDefaults.standard.string(forKey: Self.buildNameKey)
let previousVersion: String? = UserDefaults.standard.string(forKey: Self.versionNameKey)

let currentVersion: String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
let currentBuild: String = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""

var message: ConfidenceStruct = [
let message: ConfidenceStruct = [
"version": .init(string: currentVersion),
"build": .init(string: currentBuild)
]

// handle referreres
if !sourceApp.isEmpty {
message.updateValue(ConfidenceValue.init(string: sourceApp), forKey: "source-app")
}
if !url.isEmpty {
message.updateValue(ConfidenceValue.init(string: url), forKey: "source-url")
}

if eventName == "app-launched" && !isLaunched {
isLaunched = true
if previousBuild != currentBuild || previousVersion != currentVersion {
Expand Down Expand Up @@ -115,25 +101,10 @@ public class ConfidenceAppLifecycleProducer: ConfidenceEventProducer, Confidence
switch notification.name {
case UIApplication.didEnterBackgroundNotification:
updateContext(isForeground: false)
track(eventName: "enter-background")
case UIApplication.willEnterForegroundNotification:
updateContext(isForeground: true)
track(eventName: "enter-foreground")
case UIApplication.didFinishLaunchingNotification:
let options = notification.userInfo as? [UIApplication.LaunchOptionsKey: Any]
let sourceApp: String = options?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? ""
let url: String = options?[UIApplication.LaunchOptionsKey.url] as? String ?? ""
track(eventName: "app-launched", sourceApp: sourceApp, url: url)
case UIApplication.didBecomeActiveNotification:
track(eventName: "app-active")
case UIApplication.willResignActiveNotification:
track(eventName: "resign-active")
case UIApplication.didReceiveMemoryWarningNotification:
track(eventName: "memory-warning")
case UIApplication.significantTimeChangeNotification:
track(eventName: "significant-time-change")
case UIApplication.backgroundRefreshStatusDidChangeNotification:
track(eventName: "bg-refresh-status-changed")
track(eventName: "app-launched")
default:
break
}
Expand Down

0 comments on commit 488b9bd

Please sign in to comment.