Track Events
Capture how users interact with your app.
Log custom events with a single call. Attach typed properties — strings, numbers, booleans, dates — through AnyCodable for full context.
A lightweight Swift SDK that captures every event, screen and session — then streams it into B2Metric IQ for funnels, retention and churn prediction.
import UIKit
import B2MetricAnalyticsSDK
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
B2MetricAnalytics.shared.logLevel = .debug
B2MetricAnalytics.shared.start(
apiKey: "YOUR_API_KEY",
batchSize: 20,
flushInterval: 30
)
return true
}
}Quick start
Install with Swift Package Manager, initialize on launch, and log your first event.
// Xcode → File → Add Packages…
// Paste the repository URL, pick a version,
// then add B2MetricAnalyticsSDK to your app target.
dependencies: [
.package(
url: "https://github.com/b2metric",
from: "1.0.0"
)
]Capabilities
One install captures the full picture — automatic baselines plus precise, typed events you control.
Capture how users interact with your app.
Log custom events with a single call. Attach typed properties — strings, numbers, booleans, dates — through AnyCodable for full context.
Sessions and lifecycle, instrumented for you.
App opens, sessions and lifecycle moments are captured out of the box — no manual instrumentation required to get a baseline of behavior.
See the path users take, screen by screen.
Record screen views to reconstruct navigation flows and feed funnel, retention and user-flow reports inside B2Metric IQ.
Measure delivery, opens and impact.
Attribute notification deliveries and opens to downstream behavior so campaign performance is measurable end to end.
Battery- and network-friendly by design.
Events are buffered and sent in batches on a configurable interval. Tune batchSize and flushInterval to balance freshness against efficiency.
Verify your integration in real time.
Switch logLevel to .debug to stream every event and network call to the console, then flip to .off for production builds.
Configuration
Three parameters control everything. Send events instantly while debugging, then batch for battery and network efficiency in release builds.
| Parameter | Default | Type |
|---|---|---|
| apiKeyREQUIRED Your B2Metric API key. Must be non-empty. | — | String |
| batchSize Number of events to batch before sending. | 20 | Int |
| flushInterval Time in seconds between automatic flushes. | 30 | TimeInterval |
B2MetricAnalytics.shared.logLevel = .debug
B2MetricAnalytics.shared.start(
apiKey: "YOUR_DEV_API_KEY",
batchSize: 1, // send immediately
flushInterval: 5
)Event payload
Call logEvent with a name and typed properties — the SDK enriches every payload before it leaves the device.
{
"api_key": "sdk_xxxxxxxxxxxxxxxx",
"body": {
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"type": "product_viewed",
"timestamp": "2026-02-18T07:45:02.552Z",
"properties": {
"product_id": "SKU-123",
"product_name": "Running Shoes",
"category": "Footwear",
"price": 299.90
},
"user_properties": {
"app_version": "1.0.0",
"device_model": "iPhone 15 Pro",
"os_version": "17.2",
"platform": "iOS",
"country_code": "TR",
"timezone": "Europe/Istanbul"
}
}
}Documentation
From installation to troubleshooting — every page in the B2Metric Academy iOS guide.
Add the package, paste your API key, and watch events arrive in B2Metric IQ in real time.
Copyright © 2025 B2Metric | All Rights Reserved
Copyright © 2025 B2Metric | All Rights Reserved
Copyright © 2025 B2Metric | All Rights Reserved
Check your network and try again.