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: add user interactions capture #190

Merged
merged 16 commits into from
Jul 12, 2024

Conversation

PouriaAmini
Copy link
Contributor

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

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: no

@PouriaAmini PouriaAmini requested a review from crleona July 5, 2024 23:36
@PouriaAmini PouriaAmini self-assigned this Jul 5, 2024
@PouriaAmini PouriaAmini marked this pull request as draft July 8, 2024 17:33
@PouriaAmini PouriaAmini marked this pull request as ready for review July 8, 2024 18:22
Copy link
Collaborator

@crleona crleona left a comment

Choose a reason for hiding this comment

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

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

Sources/Amplitude/Constants.swift Outdated Show resolved Hide resolved
Sources/Amplitude/Events/UserInteractionEvent.swift Outdated Show resolved Hide resolved
Sources/Amplitude/Plugins/iOS/UIKitUserInteractions.swift Outdated Show resolved Hide resolved
Sources/Amplitude/Plugins/iOS/UIKitUserInteractions.swift Outdated Show resolved Hide resolved
Sources/Amplitude/Plugins/iOS/UIKitUserInteractions.swift Outdated Show resolved Hide resolved
Sources/Amplitude/Plugins/iOS/UIKitUserInteractions.swift Outdated Show resolved Hide resolved
@PouriaAmini
Copy link
Contributor Author

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
Copy link
Collaborator

crleona commented Jul 10, 2024

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
Copy link
Contributor Author

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.

@PouriaAmini PouriaAmini requested a review from crleona July 11, 2024 19:25
@crleona
Copy link
Collaborator

crleona commented Jul 11, 2024

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

@PouriaAmini PouriaAmini changed the base branch from main to feature-autocapture July 11, 2024 22:13
@PouriaAmini
Copy link
Contributor Author

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.

@PouriaAmini PouriaAmini requested a review from crleona July 12, 2024 15:25
@crleona
Copy link
Collaborator

crleona commented Jul 12, 2024

Can you please close completed comments?

@PouriaAmini PouriaAmini requested a review from crleona July 12, 2024 21:06
Copy link
Collaborator

@crleona crleona left a comment

Choose a reason for hiding this comment

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

LGTM!

@PouriaAmini PouriaAmini merged commit 83f1c92 into amplitude:feature-autocapture Jul 12, 2024
3 checks passed
PouriaAmini added a commit that referenced this pull request Aug 8, 2024
* feat: add user interactions capture (#190)

* Fix indentation issue

* feat: add user interactions capture

* fix: fix typo

* fix: remove support for UITextField action message capture

* refactor: add dispatch once for method swizzling

* fix: remove support for UISlider to reduce noise

* feat: add support for UITextField and UISlider event capture

* style: remove return keyword for one line functions

* fix: fix typo

* feat: add support for text field gained/lost focus

* fix: fix lint

* fix: remove tag as textfield title

* refactor: refactor title and shouldTrack

* refactor: add a protocol to track control elements

* feat: add support for uitextview autocapture (#195)

* Fix indentation issue

* feat: add user interactions capture

* fix: fix typo

* fix: remove support for UITextField action message capture

* refactor: add dispatch once for method swizzling

* fix: remove support for UISlider to reduce noise

* feat: add support for UITextField and UISlider event capture

* style: remove return keyword for one line functions

* fix: fix typo

* feat: add support for text field gained/lost focus

* fix: fix lint

* fix: remove tag as textfield title

* refactor: refactor title and shouldTrack

* refactor: add a protocol to track control elements

* refactor: guard on action name

* feat: add support for uitextview capture

* fix: disable action method tracking support for UITextView

* fix: fix lint issue

* style: remove amp_ prefix from objc methods

* feat: add support for gesture recognizer autocapture (#196)

* Fix indentation issue

* feat: add user interactions capture

* fix: fix typo

* fix: remove support for UITextField action message capture

* refactor: add dispatch once for method swizzling

* fix: remove support for UISlider to reduce noise

* feat: add support for UITextField and UISlider event capture

* style: remove return keyword for one line functions

* fix: fix typo

* feat: add support for text field gained/lost focus

* fix: fix lint

* fix: remove tag as textfield title

* refactor: refactor title and shouldTrack

* refactor: add a protocol to track control elements

* refactor: guard on action name

* feat: add support for uitextview capture

* fix: disable action method tracking support for UITextView

* fix: fix lint issue

* style: remove amp_ prefix from objc methods

* feat: add support for gesture recognizers autocapture

* fix: fix lint issue

* fix: exclude unsupported gestures in tvos

* fix: track touchupinside and valuechanged only (#199)

* fix: just track touchupinside and valuechanged for some elements

* fix: fix tvos issue

* feat: capture control events for autocapture (#202)

* fix: just track touchupinside and valuechanged for some elements

* fix: fix tvos issue

* feat: capture control events

* fix: remove row selected event

* fix: track touchUpInside for any element (#203)

* fix: just track touchupinside and valuechanged for some elements

* fix: fix tvos issue

* feat: capture control events

* fix: remove row selected event

* fix: track any touchUpInside

* fix: capture image name as a fallback for buttons title

* fix: deprecate defaultTracking and add autocapture (#204)

* fix: deprecate defaultTracking and add autocapture

* fix: fix schema for the new test

* fix: fix typo

* fix: fix typo

* fix: support optionset for autocapture options

* fix: fix autocaptureoptions test

* fix: fix failing test

* fix: simplified the logic to deprecate defaultTracking

* style: make autocapture options for objc as properties

* fix: disable swiftui support for autocapture (#206)

* fix: disable swiftui support for autocapture

* fix: disable support for swiftui gesture recognizers autocapture

* fix: fix typo

* fix: filter scrolls for scrollable views

* fix: imporve support for swiftui

* fix: track screen name autocapture (#207)

* fix: change element viewController to screenName

* fix: remove title since it's already captured by screenName

* fix: track changes to defaultTracking after initialization (#208)

* fix: track changes to defaultTracking after initialization

* fix: replace defaultTracking with autocapture if changed

* fix: fix typo

* fix: fix nit

* style: rename parameter name
github-actions bot pushed a commit that referenced this pull request Aug 8, 2024
# [1.8.0](v1.7.0...v1.8.0) (2024-08-08)

### Features

* Feature Autocapture ([#209](#209)) ([4ab5673](4ab5673)), closes [#190](#190) [#195](#195) [#196](#196) [#199](#199) [#202](#202) [#203](#203) [#204](#204) [#206](#206) [#207](#207) [#208](#208)
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