amplitude / Amplitude-Swift

Native iOS/tvOS/macOS/watchOS SDK
MIT License
32 stars 22 forks source link

feat: add user interactions capture #190

Closed PouriaAmini closed 3 months ago

PouriaAmini commented 3 months ago

Summary

This PR adds support for the auto-capture of user interactions with UIControl elements. To enable user interaction auto-capture, set the userInteractions parameter of the DefaultTrackingOptions initializer to true:

let amplitude = Amplitude(configuration: Configuration(
  apiKey: "API_KEY",
  defaultTracking: DefaultTrackingOptions(userInteractions = true)
))

New Automatically Captured Event

[Amplitude] User Interaction: Emitted when a user interacts with a UIControl element.

New Automatically Captured Properties

[Amplitude] Target View Class: The class name of the UI control that was touched. [Amplitude] View Controller: The class name of the View Controller that is currently visible. [Amplitude] Title: The title of the View Controller that is currently visible. [Amplitude] Target Accessibility Label: The accessibility label that is set for the control or active view controller. [Amplitude] Action Method: The name of the method that gets called when the control interaction occurs. [Amplitude] Target View Name: The variable name of the target UIView that was interacted with. [Amplitude] Target Text: The text associated with the UI control that was touched.

Checklist

PouriaAmini commented 3 months ago

How are you finding this approach compared to the a11y tree version?

@crleona - This approach seems to capture more interesting properties. It's nice to see that this works for most of the control elements in SwiftUI as well. I think the next step is to have a fallback to the accessibility tree version if no action method was fired for the interaction.

crleona commented 3 months ago

How are you finding this approach compared to the a11y tree version?

@crleona - This approach seems to capture more interesting properties. It's nice to see that this works for most of the control elements in SwiftUI as well. I think the next step is to have a fallback to the accessibility tree version if no action method was fired for the interaction.

Nice! I did not expect that we'd get SwiftUI support for free. Does this support UIGestureRecognizers as well? A11y tree fallback seems like a good next step, I'd also like to see some more complete support for standard views - things like UISwitch.isOn or begin/didEndEditing on UITextView in addition to UITextField.

PouriaAmini commented 3 months ago

How are you finding this approach compared to the a11y tree version?

@crleona - This approach seems to capture more interesting properties. It's nice to see that this works for most of the control elements in SwiftUI as well. I think the next step is to have a fallback to the accessibility tree version if no action method was fired for the interaction.

Nice! I did not expect that we'd get SwiftUI support for free. Does this support UIGestureRecognizers as well? A11y tree fallback seems like a good next step, I'd also like to see some more complete support for standard views - things like UISwitch.isOn or begin/didEndEdging on UITextView in addition to UITextField.

Yep, this supports all the SwiftUI elements that use UIControl internally, which turned out to be quite a few. The UIGestureRecognizers are not supported yet, but it should be straightforward to add support for those from KVO on the state of recognizers.

crleona commented 3 months ago

Can you please make a new auto capture feature branch and convert this PR to merge to that vs main?

PouriaAmini commented 3 months ago

Can you please make a new auto capture feature branch and convert this PR to merge to that vs main?

This PR should target a feature branch now.

crleona commented 3 months ago

Can you please close completed comments?