Card fields analytics#1817
Conversation
| func tokenize() { | ||
| guard isFormValid else { return } | ||
|
|
||
| sendAnalyticsEvent(UIComponentsAnalytics.cardFieldsSelected) |
There was a problem hiding this comment.
nit: could we callapiClient.sendAnalyticsEvent() directly here instead of going through the helper 👀
|
|
||
| // MARK: - Private Properties | ||
|
|
||
| var apiClient: BTAPIClient |
There was a problem hiding this comment.
does this need to be private 👀
There was a problem hiding this comment.
ah yep! Good call thanks
There was a problem hiding this comment.
Actually sorry it is exposed for testing like the current pattern for the other clients. I moved and added docstring to follow existing pattern
There was a problem hiding this comment.
Your comment and Jax's below sort of intersected, so ended up changing this up
| final class CardFieldsViewModelTests: XCTestCase { | ||
|
|
||
| private var mockAPIClient = MockAPIClient(authorization: "development_testing_tokenization_key_sandbox") | ||
| private var viewModel = CardFieldsViewModel( |
There was a problem hiding this comment.
nit: it looks like we're initializing the same on line 19
| private var viewModel = CardFieldsViewModel( | |
| private var viewModel = CardFieldsViewModel |
…n CardFieldsViewModelTests
| func sendAnalyticsEvent(_ event: String) { | ||
| apiClient.sendAnalyticsEvent(event) | ||
| } |
There was a problem hiding this comment.
nit: can we add a docstring to this? It took me a second to wrap my head around what was going on. Alternatively we could consider constructing the apiClient in CardFields and passing it as a param to the view model? That way we aren't constructing it twice which on fast connections could mean 2 config calls before it's in the cache. Then we can send both events in the same place. What do you think?
There was a problem hiding this comment.
yep passing the client in from CardFields works! I briefly thought about going down that road early on, but I think it makes much more sense than having this weird phantom 2nd apiClient.
There was a problem hiding this comment.
Updated again to remove the apiClient directly from the viewModel. I had to create a submitAction to house the analytics and tokenize call to use it in the onvalid closure check
Summary of changes
AI Usage
Which AI Agent Was Used?
How was AI used?
N/A: I coded this like our ancient forefathers did:
Estimated AI Code Contribution
Checklist
Authors