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 callsetUserId), 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'
endThen run:
pod installStart 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, andTugboat.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
-
Run your app with capture turned on and use it for a minute.
-
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.
-
Check
Tugboat.lifecycleState; it's.activewhile recording. -
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
| Option | Default | Description |
|---|---|---|
enabled | false | Start recording when the SDK starts. |
captureFocusChanges | false | Record when a text field gains focus (never what's typed). |
trackHostingControllers | true | Until your first .tugboatScreen appears, record unnamed SwiftUI screens under generated names. |
durableOutbox | false | Keep unsent recordings on disk and send them later, even after the app restarts. |
outboxMaxBytes | 20 MB | Disk limit for unsent recordings. |
outboxMaxAgeMs | 72 hours | Unsent recordings older than this are deleted. |
More resources
Tugboaton CocoaPods.- Source code on GitHub.
Updated about 3 hours ago