This repository contains the Countly Swift SDK, which can be integrated into iOS, iPadOS, tvOS, watchOS, macOS and visionOS applications written in Swift. The Countly Swift SDK is intended to be used with Countly Lite, Countly Flex, Countly Enterprise.
Countly is a product analytics solution and innovation enabler that helps teams track product performance and customer journey and behavior across mobile, web, and desktop applications. Ensuring privacy by design, Countly allows you to innovate and enhance your products to provide personalized and customized customer experiences, and meet key business and revenue goals.
Track, measure, and take action - all without leaving Countly.
- Questions or feature requests? Join the Countly Community on Discord
- Looking for the Countly Server? Countly Server repository
- Looking for other Countly SDKs? An overview of all Countly SDKs for mobile, web and desktop
This SDK supports the following features:
- Analytics
- Push Notifications
- User Profiles
- Crash Reports
- A/B Testing
- Performance Monitoring
- Feedback Widgets
.package(url: "https://github.com/Countly/countly-sdk-swift.git", from: "26.8.0")pod 'CountlySwift', '~> 26.8'Rich push notifications need the notification service extension subspec in your extension target:
target 'YourNotificationServiceExtension' do
pod 'CountlySwift/NotificationService', '~> 26.8'
endimport Countly
let config = CountlyConfig()
config.appKey = "YOUR_APP_KEY"
config.host = "https://your.server.ly"
Countly.shared.start(with: config)That is the whole integration. Sessions, device metrics and the device ID are handled from there.
Recording is grouped by feature rather than spread across one flat surface:
Countly.shared.events.recordEvent("purchase", segmentation: ["item": "hat"], count: 1, sum: 9.99)
let viewID = Countly.shared.views.startView("Checkout")
Countly.shared.views.stopView(id: viewID!)
Countly.shared.userProfile.setProperties(["name": "Ada", "email": "ada@example.com"])
Countly.shared.userProfile.save()With config.requiresConsent = true nothing is collected until consent is given:
Countly.shared.consent.giveConsent(for: [.sessions, .events, .viewTracking])Several instances can run side by side. Each one owns its storage, device ID, request queue, timers, log level and lifecycle observation, so one application can report to two app keys, two servers, or two tenants at once without them seeing each other's data.
let analytics = Countly.instance(named: "analytics")
analytics.start(with: analyticsConfig)Countly.instance(named:) creates the handle but never starts it, so holding a reference cannot begin collecting data by accident. Countly.shared is the default instance, and it reads and writes the same storage a previous countly-sdk-ios integration used, so an application moving to this SDK keeps its device ID and its queued requests.
Add .pushNotifications to config.features and the SDK takes over the two application delegate registration callbacks and the UNUserNotificationCenter delegate, always calling your own implementations afterwards. The device token is reported, a tapped notification records its action event, and any attached URL is opened.
Set config.disableAutomaticPushHandling = true to keep the SDK out of both delegates and forward the callbacks yourself.
Action buttons and media attachments need a notification service extension:
import UserNotifications
import CountlyNotificationService
class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
CountlyNotificationService.didReceive(request, withContentHandler: contentHandler)
}
}iOS 12, tvOS 12, watchOS 4, macOS 10.14, visionOS 1. Swift 5.9.
Security is very important to us. If you discover any issue regarding security, please disclose the information responsibly by sending an email to security@count.ly and not by creating a GitHub issue.
If you like Countly, why not use one of our badges and give a link back to us so others know about this wonderful platform?
<a href="https://count.ly/f/badge" rel="nofollow"><img style="width:145px;height:60px" src="https://countly.com/badges/dark.svg" alt="Countly - Product Analytics" /></a><a href="https://count.ly/f/badge" rel="nofollow"><img style="width:145px;height:60px" src="https://countly.com/badges/light.svg" alt="Countly - Product Analytics" /></a>Glad you asked! For community support, feature requests, and engaging with the Countly Community, please join us at our Discord Server. We're excited to have you there!
Also, we are on Twitter and LinkedIn if you would like to keep up with Countly related updates.