iOS (Swift) SDK
Native iOS SDK for JustAnalytics mobile app monitoring.
Installation#
Swift Package Manager#
Add to your Package.swift or via Xcode:
https://github.com/justanalytics/justanalytics-swift.git
CocoaPods#
# Podfile
pod 'JustAnalytics', '~> 0.1.0'
Quick Start#
import JustAnalytics
@main
struct MyApp: App {
init() {
JustAnalytics.start(
siteId: "YOUR_SITE_ID",
apiKey: "YOUR_API_KEY",
environment: .production
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Screen Tracking#
SwiftUI#
struct HomeView: View {
var body: some View {
VStack {
Text("Home")
}
.trackScreen("Home")
}
}
UIKit#
class HomeViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
JustAnalytics.trackScreen("Home")
}
}
Error Tracking#
// Automatic crash reporting is enabled by default
// Manual capture
do {
try riskyOperation()
} catch {
JustAnalytics.captureError(error, tags: ["module": "payments"])
}
Custom Events#
JustAnalytics.trackEvent("purchase_complete", properties: [
"product": "Pro Plan",
"price": 49.99,
"currency": "USD"
])
Performance Tracing#
let result = try await JustAnalytics.startSpan("load-feed") { span in
span.setAttribute("feed.type", value: "home")
let data = try await api.fetchFeed()
span.setAttribute("feed.count", value: data.count)
return data
}
User Context#
JustAnalytics.setUser(
id: "user-123",
email: "alice@example.com",
name: "Alice"
)
Network Monitoring#
// Automatically monitors URLSession requests
// Configure a custom URLSession:
let session = JustAnalytics.instrumentedSession(configuration: .default)
let (data, response) = try await session.data(from: url)
Requirements#
- iOS 15.0+
- macOS 12.0+
- watchOS 8.0+
- tvOS 15.0+
- Xcode 15.0+
- Swift 5.9+