# Screen Tracking

Track which screens your contacts visit to understand navigation patterns and build segments based on in-app behavior.


# Manual tracking

Call trackScreen in viewDidLoad or any other lifecycle method where the screen becomes active:

override func viewDidLoad() {
    super.viewDidLoad()
    UserSDK.default?.trackScreen(with: "Home")
}

The screen name is a free-form string - use whatever naming convention makes sense for your app.

TIP

trackScreen requires a contact to exist. Call ping() first if you haven't identified the contact yet. See Contact Data.


# Automatic tracking via subclassing

For controllers where you just want tracking without writing any code, subclass one of the built-in trackable view controllers. Each one calls trackScreen automatically in viewDidLoad, using the class name as the screen name.

Your base class Use instead
UIViewController TrackableViewController
UITableViewController TrackableTableViewController
UICollectionViewController TrackableCollectionViewController
UIPageViewController TrackablePageViewController
UISplitViewController TrackableSplitViewController
class HomeViewController: TrackableViewController {
    // trackScreen(with: "HomeViewController") is called automatically
}

To use a custom name instead of the class name, override screenName:

class HomeViewController: TrackableViewController {
    override var screenName: String { "Home" }
}