Screen-View Tracking (SwiftUI)

Automatically track screen views whenever a tracked SwiftUI view appears.

Overview

Sees360 can emit a system analytics event whenever a tracked SwiftUI view appears, via an explicit view modifier.

  • Event name: sees_screen_view (predefined/system)
  • Primary param: screen_name — a stable screen name you define

The API lowercases all payload keys and values before persisting/exporting.

Requirements

  • iOS 15+, SwiftUI
  • SDK initialized: Sees360.initialize(apiKey: apiKey, identifier: identifier)
  • No extra permissions required.

No single attachment point

Android’s Jetpack Compose integration wraps a whole NavController with one TrackScreenViews(nav) { destination -> screenKey } call, and every destination change is tracked automatically from that single point. SwiftUI has no equivalent navigation abstraction to hook — there’s no single object every screen change passes through the way there is with Jetpack’s NavController.

Instead, apply the .trackScreenView(name:) modifier explicitly to each view you want tracked:

struct CheckoutView: View {
    var body: some View {
        content
            .trackScreenView(name: "checkout")
    }
}

Each time this view appears, it emits sees_screen_view with screen_name set to "checkout".

Quick start

  1. Initialize the SDK.
  2. Add .trackScreenView(name:) to each SwiftUI view you want tracked as a screen.
  3. Use stable, lowercase keys for each screen.
Sees360.initialize(apiKey: apiKey, identifier: identifier)

struct HomeView: View {
    var body: some View {
        content
            .trackScreenView(name: "home")
    }
}

struct DetailsView: View {
    var body: some View {
        content
            .trackScreenView(name: "details")
    }
}

struct SettingsView: View {
    var body: some View {
        content
            .trackScreenView(name: "settings")
    }
}

Best practices

  • Stable keys only. No IDs or ephemeral UI state in screen_name (e.g., use profile, not profile:42).
  • One modifier per logical screen. Applying .trackScreenView(name:) to multiple nested views that all appear together will fire multiple events — apply it at the top-level view for that screen.
  • Cross-platform alignment. Use the same keys on Android/iOS for consistent dashboards.

Troubleshooting

  • No events firing: Confirm the modifier is actually attached to a view that’s part of the rendered hierarchy — a modifier on a view that’s conditionally never shown never fires .onAppear.
  • Duplicate events: Check that .trackScreenView(name:) isn’t applied more than once to views that appear together (e.g. both a container and its content).
  • Unexpected names: .trackScreenView(name:) always uses exactly the string you pass — there’s no automatic derivation to override here, unlike UIKit’s class-name fallback.

Event reference

  • Name: sees_screen_view
  • Payload (lowercased by backend):
    • screen_name: String — canonical screen key (lowercase)
{
  "event_name": "sees_screen_view",
  "payload": { "screen_name": "settings" }
}

Privacy & security

  • Avoid logging sensitive data (API keys, identifiers).
  • If your app supports analytics opt-out, call setAnalyticsConsent(granted: false).

Do not include PII in screen_name.


This site uses Just the Docs, a documentation theme for Jekyll.