iOS and macOS (Swift)

The Hey Glancy Swift package runs on iOS 13+, iPadOS, macOS 10.15+, tvOS 13+ and watchOS 6+, with no dependencies. It sends events, screen views and app lifecycle events, and keeps events on disk while the device is offline.

Install

In Xcode, choose File → Add Package Dependencies…, enter the URL below, pick Up to Next Major Version and add the Glancy product to your app target:

https://github.com/caravela-labs/glancy-swift

Or in Package.swift:

.package(url: "https://github.com/caravela-labs/glancy-swift", from: "0.1.3"),
// in your target's dependencies:
.product(name: "Glancy", package: "glancy-swift")

Set up

Call setup once when the app starts, with the write key from your bucket's Setup page.

SwiftUI:

import Glancy

@main
struct KitboxApp: App {
    init() {
        Glancy.setup(writeKey: "YOUR_WRITE_KEY", host: URL(string: "https://ingest.heyglancy.com")!)
    }

    var body: some Scene {
        WindowGroup {
            HomeView().glancyScreen("Home") // a screen view each time it appears
        }
    }
}

UIKit: call setup in application(_:didFinishLaunchingWithOptions:), and send screen views from viewDidAppear:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    Glancy.shared?.screen("Cart")
}

Events and users

Glancy.shared?.track("Order Completed", properties: ["revenue": 42, "currency": "EUR"])

// after sign in
Glancy.shared?.identify(user.id, traits: ["name": user.name, "email": user.email])

// on sign out
Glancy.shared?.reset()

Properties and traits can be strings, numbers, booleans, dates, URLs, arrays and dictionaries.

App lifecycle

On by default:

Event When
Application Installed The first launch
Application Updated The first launch after CFBundleShortVersionString or CFBundleVersion changed
Application Opened Each launch, and each return to the foreground (from_background: true)
Application Backgrounded The app goes to the background; the queue is sent right away

Every event also carries the device model (for example iPhone16,2), OS version, screen size, locale, time zone and app version.

Options

Glancy.setup(writeKey: "YOUR_WRITE_KEY", host: URL(string: "https://ingest.heyglancy.com")!) { config in
    config.flushAt = 20                         // events per batch
    config.flushInterval = 30                   // seconds between batches
    config.maxQueueSize = 1000                  // events kept while offline
    config.trackApplicationLifecycleEvents = true
    config.debug = false                        // log every event
}

Events waiting to be sent are kept in Application Support and retried with back-off, so they survive the app being closed or the device going offline.