Support SwiftUI screen names through accessibilityIdentifier and friends
Problem Statement
Screen names are auto generated, so autocapture does not work well nor the detection of the current screen for session replay
Solution Brainstorm
fallback to accessibilityIdentifier or friends if available
https://github.com/PostHog/posthog-ios/blob/e35ec56b8e25d759e285d9a7d831eed070bf3cd3/PostHog/UIViewController.swift#L55 https://github.com/PostHog/posthog-ios/blob/e35ec56b8e25d759e285d9a7d831eed070bf3cd3/PostHog/Replay/PostHogReplayIntegration.swift#L476
afaik accessibilityIdentifier isn't available at runtime for production builds, what we could do is wrap the view:
var body: some View {
PostHogView("Name"){
List {
...
}
}
}
in this case, we can read the Name at runtime but it's not much different than calling PostHog.screen("Name"), all screens need to be wrapped.
Another option would be to use the objc_getAssociatedObject and objc_setAssociatedObject as an extension method to UIKit and SwiftUI views
Edit: not possible either since the associated objects are different when scanning the view tree
closed by https://posthog.com/docs/libraries/ios#capturing-screen-views-in-swiftui