Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): Improve iOS Capturing screen views documentation #9675

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ If you want to manually send a new screen capture event, use the `screen` functi
PostHogSDK.shared.screen("Dashboard", properties: ["fromIcon": "bottom"])
```

### Capturing screen views in SwiftUI

In SwiftUI, views can exist at multiple levels of abstraction, making automatic tracking challenging. A SwiftUI view might represent an entire screen, similar to a `UIViewController`, but it could also represent much smaller UI components, like `UIControl` or `UIView` elements. Because SwiftUI doesn’t clearly distinguish between these levels of views in the same way UIKit does, it becomes difficult to reliably auto-track "screen" (as in full-screen) views.
> **Important:** Please note that `captureScreenViews` configuration is intented for `UIKit` use. For `SwiftUI` screen captures, please see the following section.

Moreover, because of SwiftUI's declarative nature and dynamic view construction, SwiftUI views may sometimes lack clear, static names that are suitable for analytics purposes.
### Capturing screen views in SwiftUI

To track a screen view, you can explicitly apply the `postHogScreenView` view modifier to your full-screen view. While the PostHog iOS SDK will attempt to infer the screen's name based on the view's `Type`, you can also pass a custom screen name that better describes your view, along with optional event properties.
To track a screen view in `SwiftUI`, apply the `postHogScreenView` modifier to your full-screen views. The PostHog iOS SDK will infer a screen name based on the view’s type, but you can provide a custom name and event properties if needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes me think of https://posthog.com/docs/product-analytics/autocapture#capturing-additional-properties-in-autocapture-events where people can autocapture arbitrary properties by decorating the DOM

would be a good extension to mobile autocapture too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


```swift
// This will trigger a screen view event with $screen_name: "HomeViewContent"
Expand All @@ -60,4 +58,6 @@ struct HomeView: View {
.postHogScreenView("My Home View", ["from_button": "start"])
}
}
```
```

In SwiftUI, views can range from entire screens to small UI components. Unlike UIKit, SwiftUI doesn’t clearly distinguish between these levels, which makes automatic tracking of full-screen views harder.
Loading