In my previous post I was showing how easy it is to distribute an app using App Center. This time I’d like to take a look at the diagnostics and analytics that App Center offers to the developers.
Prerequirements
If you have a fresh project make sure to enable CocoaPods in it.
sudo gem update xcodeproj
then add AppCenter to Podfile
target 'AppCenterIosAuomate' do
use_frameworks!
pod 'AppCenter'
end
after that install the pod
pod install
Integrate with an app
Integration is almost as easy as the installation. We need to start AppCenter from AppDelegate.
import UIKit
import AppCenter
import AppCenterAnalytics
import AppCenterCrashes
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppCenter.start(withAppSecret: "{secret}", services:[
Analytics.self,
Crashes.self
])
return true
}
}
if you don’t use an AppDelegate you can initialize it in a different place. For example if you are building an app using SwiftUI you may need to update the App class
import AppCenter
import AppCenterAnalytics
import AppCenterCrashes
import SwiftUI
@main
struct AppCenterIosAuomateApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
init() {
AppCenter.start(withAppSecret: "{your-key}", services:[
Analytics.self,
Crashes.self
])
}
}
Make sure to use some safe tools to secure your key.
Analytics
First let’s prepare something that we would be able to look into. I am using SwiftUI to create two buttons in my view. One will be used for analytics and the other for crash.
import SwiftUI
import AppCenterAnalytics
struct ContentView: View {
private var x = 0
private var y = 0
var body: some View {
VStack {
Button("Log Event"){
Analytics.trackEvent("Log event clicked")
}
Button("Crash") {
Analytics.trackEvent("Crash clicked")
let result = x/y
}
}
.padding()
}
}
So what’s the purpose? Let’s do a test. Make the changes and commit the code. When the build is ready and available – install new version. Try clicking „Log Event” few times and then „Crash”. Of course the app will crash and that’s the point. After few short moments dive into analytics tab.
Inside analytics view you should see a standard information like number of unique users, number of sessions, length of sessions. Inside the events tab you can find the list of events that were performed and logged to App Center. Each one gives a brief information of users, overall count and counter per user.
The Log Flow tab will let you see the actions in real time. You can keep it opened and click the Log Event or Crash. You should see them in a short moment coming to Log Flow tab. This is useful especially at the beginning to see if your App Center Analytics is properly configured.
Diagnostics
Inside the diagnostics tab you can see crashes and errors. The crash definitions contain stack traces as well as some generic information what type of devices were impacted, language, OS and version. The biggest advantage is that if you uploaded symbols there is a full stack trace pointing to a line of code were the crash occurred.
If you set a proper build in App Center then the symbols are automatically uploaded during each build. In a case when you install manually app to device or skipping App Center you have to prepare an archiv, zip the symbols folder from the archive and upload it manually to App Center.
Note that crash data will not be pushed if you are running an app in debug mode.
Summary
App Center gives a basic tooling for analytics and diagnostics. It’s biggest advantage is that it is very easy to integrate and basic crash information is stored almost out of the box if you use the App Center to also distribute your app.
However both features compared to a dedicated platforms like Mixpanel (analytics) or Sentry (error diagnostics) looks only like a child’s toy. Yet if you decide to use App Center for build management it’s worth to include the App Center crash diagnostics as well with only just a few lines of code.