posthog-ios icon indicating copy to clipboard operation
posthog-ios copied to clipboard

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

Open jadar opened this issue 1 year ago • 3 comments

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.

jadar avatar Nov 08 '24 21:11 jadar

@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

ioannisj avatar Nov 08 '24 22:11 ioannisj

Hey @ioannisj, here is an example project.

PostHogIssue244Example.zip

jadar avatar Nov 08 '24 23:11 jadar

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.

marandaneto avatar Nov 11 '24 13:11 marandaneto