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

chore: add SwiftUI View extensions to capture screen view and views in general (postHogViewSeen, postHogScreenView) #180

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

marandaneto
Copy link
Member

@marandaneto marandaneto commented Sep 5, 2024

💡 Motivation and Context

Spike for "semi automatic" or more UX friendly #167

Screen view (applied to the root view)

var body: some Scene {
        WindowGroup {
            ContentView()
                .postHogScreenView() // will infer the class name (ContentView)
        }
    }

Widget view (applied to any view)

Button(action: triggerAction) {
    Text("My Text!")
}.postHogViewSeen("My Button")

Events will be captured when the View triggers the onAppear method

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

@marandaneto marandaneto marked this pull request as ready for review September 5, 2024 10:15
@marandaneto marandaneto requested a review from a team September 5, 2024 10:15
func postHogViewEvent(_ event: String,
_ properties: [String: Any]? = nil) -> some View
{
modifier(PostHogSwiftUIViewModifier(viewEventName: event,
Copy link
Member Author

@marandaneto marandaneto Sep 5, 2024

Choose a reason for hiding this comment

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

I cannot use type(of: self) here because it will be Button<Text> for all buttons

Copy link

@daibhin daibhin left a comment

Choose a reason for hiding this comment

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

Left a comment but up to you to decide

@marandaneto marandaneto changed the title chore: add SwiftUI View extensions to capture screen view and views in general (postHogViewEvent, postHogScreenView) chore: add SwiftUI View extensions to capture screen view and views in general (postHogViewSeen, postHogScreenView) Sep 5, 2024
@marandaneto marandaneto merged commit e9b8f2b into main Sep 5, 2024
9 checks passed
@marandaneto marandaneto deleted the chore/swiftui-extensiob branch September 5, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants