Swiftpack.co -  TelemetryDeck/SwiftClient as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
TelemetryDeck/SwiftClient
This is the Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
.package(url: "https://github.com/TelemetryDeck/SwiftClient.git", from: "1.1.4")

TelemetryClient

Init the Telemetry Manager at app startup, so it knows your App ID (you can retrieve the App ID in the Telemetry Viewer app, under App Settings)

let configuration = TelemetryManagerConfiguration(appID: "<YOUR-APP-ID>")
// optional: modify the configuration here
TelemetryManager.initialize(with: configuration)

For example, if you're building a scene based app, in the init() function for your App:

import SwiftUI
import TelemetryClient

@main
struct TelemetryTestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
    
    init() {
        // Note: Do not add this code to `WindowGroup.onAppear`, which will be called 
        //       *after* your window has been initialized, and might lead to our initialization
        //       occurring too late.
        let configuration = TelemetryManagerConfiguration(appID: "<YOUR-APP-ID>")
        TelemetryManager.initialize(with: configuration)
    }
}

Then send signals like so:

TelemetryManager.send("appLaunchedRegularly")

Debug Mode

Telemetry Manager will not send any signals if your scheme's build configuration is set to "Debug", e.g if #if DEBUG would evaluate to true. You can override this by setting configuration.sendSignalsInDebugConfiguration = true on your TelemetryManagerConfiguration instance.

User Identifiers

Telemetry Manager will create a user identifier for you user that is specific to app installation and device. If you have a better user identifier available, such as an email address or a username, you can use that instead, by passing it on to the TelemetryManagerConfiguration (the identifier will be hashed before sending it).

configuration.defaultUser = "myuser@example.com"

You can update the configuration after TelemetryManager is already initialized.

Payload

You can also send additional payload data with each signal:

TelemetryManager.send("databaseUpdated", with: ["numberOfDatabaseEntries": "3831"])

Telemetry Manager will automatically send a base payload with these keys:

  • platform
  • systemVersion
  • appVersion
  • buildNumber
  • isSimulator
  • isTestFlight
  • isAppStore
  • modelName
  • architecture
  • operatingSystem
  • targetEnvironment

Sessions

With each Signal, the client sends a hash of your user ID as well as a session ID. This gets automatically generated when the client is initialized, so if you do nothing, you'll get a new session each time your app is started from cold storage.

On iOS, tvOS, and watchOS, the session identifier will automatically update whenever your app returns from background, or if it is launched from cold storage. On other platforms, a new identifier will be generated each time your app launches. If you'd like more fine-grained session support, write a new random session identifier into the TelemetryManagerConfiguration's sessionID property each time a new session begins.

GitHub

link
Stars: 50
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Version 1.1.4
1 week ago

This bugfix release fixes a compile error on macOS < 11 discovered by @biocross. Thanks for reporting 🚀

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics