PostHog / posthog-ios

PostHog iOS SDK
https://posthog.com/docs/libraries/ios
MIT License
38 stars 43 forks source link

Autocapture of screen views doesn't handle custom container view controllers #244

Open jadar opened 5 days ago

jadar commented 5 days ago

Version

3.13.3

Steps to Reproduce

  1. Add a custom container view controller that will swap views based on some state. For example, we have an InitialViewController that either shows the login screen or our app depending on the login state.
  2. Add PostHog with autocapture enabled
  3. Observe events coming in as screen view for the Initial screen, even when the other screens are being visited.

Expected Result

Each screen even has the unique name of the View controller being visited.

Actual Result

Each event has the same view controller at the base of our hierarchy. Ours is called InitialViewController.

ioannisj commented 5 days ago

@jadar Do you mind sharing a small sample project with the layout you described? I'm sure it's the way we traverse the view hierarchy to find a root view controller. Having a sample project will help out a lot. Want to be a bit extra careful with screen names so that we don't break any existing user's data either. Thanx

jadar commented 5 days ago

Hey @ioannisj, here is an example project.

PostHogIssue244Example.zip

marandaneto commented 3 days ago

As a workaround, you can use the propertiesSanitizer and change the $screen_name and replace it with the correct name. Another option is to disable captureScreenViews and capture all screen views with PostHogSDK.shared.screen(name).

I'm not sure we're gonna find a way to make it work with every possible configuration since the naming is based on heuristics and is best-effort, but of course, if there's a fix on our end, that would be cool.