iOS

Add the Tugboat SDK to your native iOS app.

Add Tugboat to a native iOS app built with SwiftUI. You'll need your iOS app's SDK key. See SDK overview.

Requirements

  • iOS 15 or later
  • Swift 5.9 and Xcode 15 or later
  • CocoaPods. The iOS SDK isn't available through Swift Package Manager.
  • Your app's App Store privacy details must include what the SDK collects. The SDK's privacy manifest (PrivacyInfo.xcprivacy) declares, for analytics and not for tracking: the device's vendor identifier, a user ID (only if you call setUserId), product interactions, masked screenshots, and performance data.

Install

Add the pod to your Podfile:

platform :ios, '15.0'

target 'MyApp' do
  pod 'Tugboat', '0.1.3'
end

Then run:

pod install

Start the SDK

Start Tugboat once, as your app launches, before its first screen appears. In a SwiftUI app, use an app delegate:

import SwiftUI
import Tugboat

final class AppDelegate: NSObject, UIApplicationDelegate {
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
  ) -> Bool {
    let info = Bundle.main.infoDictionary
    Tugboat.start(TugboatConfig(
      collector: .init(
        baseURL: URL(string: "https://collector.gettugboat.com")!,
        apiKey: tugboatSdkKey // your iOS app's SDK key
      ),
      app: .init(
        name: "My App",
        version: info?["CFBundleShortVersionString"] as? String ?? "",
        buildNumber: info?["CFBundleVersion"] as? String ?? "",
        appId: Bundle.main.bundleIdentifier ?? ""
      ),
      enabled: true
    ))
    return true
  }
}

@main
struct MyApp: App {
  @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
  var body: some Scene {
    WindowGroup { ContentView() }
  }
}

All app fields and both collector fields are required. If one is blank, the SDK doesn't start and logs which field is missing.

Turn capture on

Capture is off by default. Either:

  • set enabled: true, as above, to record from launch, or
  • leave it off and call Tugboat.activate(activationRequestId: "...") when you want to start recording, and Tugboat.deactivate() to stop.

Name your screens

In SwiftUI, name each screen with .tugboatScreen:

OrdersView()
  .tugboatScreen("Orders")

FiltersView()
  .tugboatScreen("Filters", presentation: .sheet)
  • Give each tab its own navigator with .tugboatNavigator("Home"), and name the screens inside it.
  • Give important controls a stable name with .tugboatTag("checkout").
  • UIKit view controllers aren't recorded as screens yet.

Don't put personal data in screen names or tags.

Identify users

Tugboat.setUserId("user-123")
Tugboat.setTraits(["plan": "pro"])

Pass nil to setUserId to clear it, for example when someone signs out.

Capture network calls

Use a session from Tugboat in place of your own URLSession:

let session = Tugboat.instrumentedSession(
  configuration: .default,
  routeResolver: { request in routeFor(request) } // e.g. "/orders/{id}"
)

Or record a single request:

let (data, response) = try await Tugboat.data(for: request, route: "/orders/{id}")

The route is the path Tugboat records. Use a pattern such as /orders/{id} so IDs stay out of it. Requests on URLSession.shared aren't recorded unless you use Tugboat.data(for:route:).

By hand:

let call = Tugboat.beginNetworkCall(method: "POST", route: "/projects")
call.complete(statusCode: 201)

Send events

let events = Tugboat.eventHook(source: "analytics", parameterPolicy: .allowList(["method"]))
events.record("USER_LOGIN", parameters: ["method": "email"])

The parameter policy decides which parameters are sent: .allowAll (the default), .namesOnly, .allowList or .transform. Use the narrowest one that works, because .allowAll can send search terms, IDs or other user content.

Mark sensitive content

All text and images are masked by default, and web views are masked whole. To always mask a SwiftUI view:

AccountNumberView(number: account.number)
  .tugboatSensitive()

It masks the view's frame; shadows or content drawn outside it aren't covered. See Privacy and masking.

Verify your setup

  1. Run your app with capture turned on and use it for a minute.

  2. Stream the SDK's logs:

    xcrun simctl spawn booted log stream --level debug --predicate 'subsystem == "com.gettugboat.sdk"'

    Problems such as missing fields are logged there.

  3. Check Tugboat.lifecycleState; it's .active while recording.

  4. Open Findings › Sessions › All sessions in Tugboat and find your session.

Pause or stop capture

  • Tugboat.deactivate() stops recording and keeps your settings, so you can activate again.
  • Tugboat.stop() ends the session and forgets your settings.
  • Tugboat.clearPendingData() deletes recordings that haven't been sent yet.

Troubleshooting

Nothing is recorded

Check the logs for Tugboat not started. Make sure every app field is filled in, including version and build number, and that capture is on (enabled: true or a call to activate).

Screenshots are fully masked

While SwiftUI content is on screen, the SDK masks the whole screen on iOS versions Tugboat hasn't verified yet (currently anything other than iOS 26 and 27), and while content is animating. Replays from those devices show layout and taps, but less detail.

Recordings arrive late

Without durableOutbox, recordings that weren't sent before the app went to the background are sent the next time it comes to the foreground.

Configuration options

OptionDefaultDescription
enabledfalseStart recording when the SDK starts.
captureFocusChangesfalseRecord when a text field gains focus (never what's typed).
trackHostingControllerstrueUntil your first .tugboatScreen appears, record unnamed SwiftUI screens under generated names.
durableOutboxfalseKeep unsent recordings on disk and send them later, even after the app restarts.
outboxMaxBytes20 MBDisk limit for unsent recordings.
outboxMaxAgeMs72 hoursUnsent recordings older than this are deleted.

More resources


Did this page help you?