Aptabase is alsoavailable through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Aptabase', :git => 'https://github.com/aptabase/aptabase-swift.git', :tag => '0.1.0'
Usage
If you’re targeting macOS, you must first enable the Outgoing Connections (Client) checkbox under the App Sandbox section.
First you need to get your App Key from Aptabase, you can find it in the Instructions menu on the left side menu.
Initialized the SDK as early as possible in your app, for example:
import SwiftUI
import Aptabase
@main
struct ExampleApp: App {
init() {
Aptabase.shared.initialize(appKey: "<YOUR_APP_KEY>") // 👈 this is where you enter your App Key
}
var body: some Scene {
WindowGroup {
MainView()
}
}
}
Afterwards you can start tracking events with trackEvent:
import Aptabase
Aptabase.shared.trackEvent("connect_click") // An event with no properties
Aptabase.shared.trackEvent("play_music", with: ["name": "Here comes the sun"]) // An event with a custom property
A few important notes:
The SDK will automatically enhance the event with some useful information, like the OS, the app version, and other things.
You’re in control of what gets sent to Aptabase. This SDK does not automatically track any events, you need to call trackEvent manually.
Because of this, it’s generally recommended to at least track an event at startup
The trackEvent function is a non-blocking operation as it runs on the background.
Only strings and numbers values are allowed on custom properties
Swift SDK for Aptabase
Instrument your apps with Aptabase, an Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps.
Install
Option 1: Swift Package Manager
Add the following lines to your
Package.swift
file:Option 2: Adding package dependencies with Xcode
Use this guide to add
aptabase-swift
to your project. Use https://github.com/aptabase/aptabase-swift for the url when Xcode asks.Option 3: CocoaPods
Aptabase is alsoavailable through CocoaPods. To install it, simply add the following line to your Podfile:
Usage
First you need to get your
App Key
from Aptabase, you can find it in theInstructions
menu on the left side menu.Initialized the SDK as early as possible in your app, for example:
Afterwards you can start tracking events with
trackEvent
:A few important notes:
trackEvent
manually.trackEvent
function is a non-blocking operation as it runs on the background.Preparing for Submission to Apple App Store
When submitting your app to the Apple App Store, you’ll need to fill out the
App Privacy
form. You can find all the answers on our How to fill out the Apple App Privacy when using Aptabase guide.