Skip to content

Commit

Permalink
Forward mixpanel and bugsnag keys > info.plist
Browse files Browse the repository at this point in the history
  • Loading branch information
dbart01 committed Nov 30, 2023
1 parent 3fc8a6d commit 2c95f3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
10 changes: 10 additions & 0 deletions Code/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,15 @@
</array>
<key>UIUserInterfaceStyle</key>
<string>Dark</string>
<key>mixpanel</key>
<dict>
<key>apiKey</key>
<string>>$(MIXPANEL)</string>
</dict>
<key>bugsnag</key>
<dict>
<key>apiKey</key>
<string>>$(BUGSNAG)</string>
</dict>
</dict>
</plist>
14 changes: 7 additions & 7 deletions Code/Utilities/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ typealias AnalyticsValue = MixpanelType

enum Analytics {

private static var isRegistered: Bool = false

static func initialize() {
FirebaseApp.app()?.isDataCollectionDefaultEnabled = true
Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(true)

if let apiKey = Environment.variable(.mixpanel) {
if
let plist = Bundle.main.infoDictionary,
let mixpanel = plist["mixpanel"] as? [String: String],
let apiKey = mixpanel["apiKey"]
{
Mixpanel.initialize(token: apiKey)
isRegistered = true
trace(.success, components: "Starting Mixpanel...")
trace(.success, components: "Initializing Mixpanel...")
} else {
trace(.failure, components: "Failed to start Mixpanel. No API key provided in the '\(Environment.Variable.mixpanel.rawValue)' env variable.")
trace(.failure, components: "Failed to initialize Mixpanel. No API key found in Info.plist")
}
}

Expand All @@ -46,7 +47,6 @@ enum Analytics {
}

private static func track(_ name: String, properties: [String: AnalyticsValue]? = nil) {
guard isRegistered else { return }
mixpanel.track(event: name, properties: properties)
}
}
Expand Down
14 changes: 1 addition & 13 deletions Code/Utilities/ErrorReporting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,11 @@ import CodeServices

enum ErrorReporting {

private static var isRegistered: Bool = false

static func initialize() {
if let apiKey = Environment.variable(.bugsnag) {
Bugsnag.start(withApiKey: apiKey)
isRegistered = true
trace(.success, components: "Starting Bugsnag...")
} else {
trace(.failure, components: "Failed to start BugSnag. No API key provided in the '\(Environment.Variable.bugsnag.rawValue)' env variable.")
}
Bugsnag.start()
}

static func breadcrumb(_ breadcrumb: Breadcrumb) {
guard isRegistered else { return }

Bugsnag.leaveBreadcrumb(withMessage: breadcrumb.rawValue)
}

Expand Down Expand Up @@ -53,8 +43,6 @@ enum ErrorReporting {
}

private static func capture(_ error: Swift.Error, reason: String? = nil, file: String = #file, function: String = #function, line: Int = #line, buildUserInfo: (inout [String: Any]) -> Void) {
guard isRegistered else { return }

let swiftError = error as NSError

var userInfo: [String: Any] = [:]
Expand Down

0 comments on commit 2c95f3b

Please # to comment.