Screen Lifecycle Instrumentation
Generates: Spans
Automatically tracks UIViewController transitions and emits spans for each screen's creation, appearance, and active session.
How It Works
The SDK swizzles UIViewController.viewDidLoad, viewWillAppear, and viewDidDisappear at the class level. Every UIViewController subclass is tracked automatically — no per-screen code is needed.
Configuration
Screen lifecycle tracking is enabled by default.
Pulse.shared.initialize(
endpointBaseUrl: "https://your-backend.com",
apiKey: "your-api-key",
instrumentations: { config in
config.screenLifecycle { $0.enabled(true) } // default: true
}
)
What Gets Tracked
| Event | Span Name | Triggered By |
|---|---|---|
| First load | Created | viewDidLoad |
| Reappearing from background/navigation | Restarted | viewWillAppear (after disappear) |
| Leaving the screen | Stopped | viewDidDisappear |
| Time screen was active (appear → disappear) | ViewControllerSession | Closed on viewDidDisappear |
Generated Telemetry
Type: Span
Span Kind: Internal
pulse.type: screen_load (Created/Restarted spans) · screen_session (ViewControllerSession span)
Attributes
| Attribute | Description | Example | Always Present |
|---|---|---|---|
pulse.type | "screen_load" for load spans, "screen_session" for session span | "screen_session" | ✅ Yes |
screen.name | UIViewController class name | "CheckoutViewController" | ✅ Yes |
session.id | Current session identifier | "f40364c92b85ec0c19c35a65be42b97f" | ✅ Yes |
Sample Payload
{
"name": "ViewControllerSession",
"kind": "INTERNAL",
"attributes": {
"pulse.type": "screen_session",
"screen.name": "ProductDetailViewController",
"session.id": "f40364c92b85ec0c19c35a65be42b97f"
}
}
SwiftUI
Screen lifecycle instrumentation tracks UIViewController — it does not automatically track SwiftUI View navigation. Apps that use UIHostingController wrapping SwiftUI views will see the hosting controller tracked (with its class name). Pure SwiftUI navigation (e.g., NavigationStack pushes) does not create screen lifecycle spans.
Disabling Screen Lifecycle Instrumentation
config.screenLifecycle { $0.enabled(false) }