Skip to content

Commit

Permalink
Reduced compilation duration (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
art-divin authored May 5, 2024
1 parent f6f3a7f commit eded4ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
8 changes: 7 additions & 1 deletion Sources/Segment/Plugins/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ public class Context: PlatformPlugin {
app.merge(localizedInfo) { (_, new) in new }
}
if app.count != 0 {
var name: String = ""
if let displayName = app["CFBundleDisplayName"] as? String {
name = displayName
} else if let displayName = app["CFBundleName"] as? String {
name = displayName
}
staticContext["app"] = [
"name": app["CFBundleDisplayName"] ?? app["CFBundleName"] ?? "" ,
"name": name,
"version": app["CFBundleShortVersionString"] ?? "",
"build": app["CFBundleVersion"] ?? "",
"namespace": Bundle.main.bundleIdentifier ?? ""
Expand Down
45 changes: 23 additions & 22 deletions Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,36 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle {
return
}

let previousVersion = UserDefaults.standard.string(forKey: Self.versionKey)
let previousBuild = UserDefaults.standard.string(forKey: Self.buildKey)

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

if previousBuild == nil {
analytics?.track(name: "Application Installed", properties: [
"version": currentVersion ?? "",
"build": currentBuild ?? ""
])
} else if currentBuild != previousBuild {
let previousVersion: String? = UserDefaults.standard.string(forKey: Self.versionKey)
let previousBuild: String? = UserDefaults.standard.string(forKey: Self.buildKey)

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

if let previousBuild,
currentBuild != previousBuild {
analytics?.track(name: "Application Updated", properties: [
"previous_version": previousVersion ?? "",
"previous_build": previousBuild ?? "",
"version": currentVersion ?? "",
"build": currentBuild ?? ""
"previous_build": previousBuild,
"version": currentVersion,
"build": currentBuild
])
} else {
analytics?.track(name: "Application Installed", properties: [
"version": currentVersion,
"build": currentBuild
])
}
let sourceApp: String? = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? ""
let url: String? = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? ""

let sourceApp: String = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? ""
let url: String = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? ""

analytics?.track(name: "Application Opened", properties: [
"from_background": false,
"version": currentVersion ?? "",
"build": currentBuild ?? "",
"referring_application": sourceApp ?? "",
"url": url ?? ""
"version": currentVersion,
"build": currentBuild,
"referring_application": sourceApp,
"url": url
])

UserDefaults.standard.setValue(currentVersion, forKey: Self.versionKey)
Expand Down

0 comments on commit eded4ac

Please sign in to comment.