Skip to main content

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

EventSpan NameTriggered By
First loadCreatedviewDidLoad
Reappearing from background/navigationRestartedviewWillAppear (after disappear)
Leaving the screenStoppedviewDidDisappear
Time screen was active (appear → disappear)ViewControllerSessionClosed on viewDidDisappear

Generated Telemetry

Type: Span
Span Kind: Internal
pulse.type: screen_load (Created/Restarted spans) · screen_session (ViewControllerSession span)

Attributes

AttributeDescriptionExampleAlways Present
pulse.type"screen_load" for load spans, "screen_session" for session span"screen_session"✅ Yes
screen.nameUIViewController class name"CheckoutViewController"✅ Yes
session.idCurrent 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) }