-
Notifications
You must be signed in to change notification settings - Fork 135
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
[Woo POS] Tracking preparaion #11537
[Woo POS] Tracking preparaion #11537
Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #11537 +/- ##
============================================
- Coverage 40.22% 39.39% -0.83%
- Complexity 5206 5210 +4
============================================
Files 1089 1092 +3
Lines 63521 63573 +52
Branches 8723 8727 +4
============================================
- Hits 25549 25047 -502
- Misses 35665 36217 +552
- Partials 2307 2309 +2 ☔ View full report in Codecov by Sentry. |
@@ -1,1057 +1,1066 @@ | |||
package com.woocommerce.android.analytics | |||
|
|||
enum class AnalyticsEvent(val siteless: Boolean = false) { | |||
interface IAnalyticsEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd want to avoid doing so, but with current enum
usage I didn't find a way to reuse current AnalyticsTrackers*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not aware of a better option so it seems worth it to make this change. Should be a good foundation as POS expands.
) : ScopedViewModel(savedStateHandle) { | ||
init { | ||
launch { | ||
analyticsTracker.track(WooPosAnalytics.Event.Test) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for testing. Let's remove that before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice:
2024-05-21 16:04:02.385 8173-8684 WooCommerce-UTILS com.woocommerce.android.dev I 🔵 Tracked: woo_pos_test_event, Properties: {"blog_id":227901557,"is_wpcom_store":true,"was_ecommerce_trial":true,"plan_product_slug":"business-bundle","store_id":"79059489-918b-4632-9fee-465239092a2e","is_debug":true,"site_url":"https:\/\/woo-totally-selfless-bear.wpcomstaging.com","cached_woo_core_version":"8.9.1"}
savedStateHandle: SavedStateHandle, | ||
) : ScopedViewModel(savedStateHandle) | ||
) : ScopedViewModel(savedStateHandle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shell we actually reuse ScopedViewModel
? That couples us to the main code but gives some reduction in the complexity of the POS. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The understanding I have is that we no longer have to worry as much about keeping things decoupled. Rather we want what is faster, as long as it's still correct. Then we would commit to spending the additional time later, after this stage of the POS is done, to go back and decouple. So it should be fine to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@backwardstruck It's quite interesting, but I understand it differently. Even though we've chosen not to use modularization, we still need to build it in a decoupled way. This means we are incorporating the unfavorable aspects of both approaches, but that's my understanding 🤔
@samiuelson what's your take on this? =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the real question is if we want to reuse the Event
class (for navigation), and the event triggering mechanism, the ScopedViewModel
introduces. Other parts like the CoroutineScope
interface, are not useful, IMO. Unless we realize we need it, I'd suggest getting rid of another layer of inheritance and extending the ViewModel class directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also dislike the idea of ScopedViewModel
"being" a CoroutineScope
itself – it's not very helpful and makes code harder to debug and read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I create an issue on getting rid ScopedViewModel
and the events from the main app. We should probably take this one sooner while we still have 1-2 places where it is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/analytics/AnalyticsEvent.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the new implementation and existing analytics against regressions. LGTM!
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper, | ||
private val commonPropertiesProvider: WooPosAnalyticsCommonPropertiesProvider | ||
) { | ||
suspend fun track(analytics: IAnalyticsEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kidinov sorry for chiming here again, just one question here for my learning, since you worked on making the tracking done on a background thread before (#11293), what's the usefulness of making this suspendable
?
And one suggestion, if you don't mind: if this has to be suspendable,
I think a more appropriate dispatcher to use would be Dispatchers.Default
, Dispatchers.IO
is destined more for blocking IO operations, which is not the case here, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hichamboushaba 👋
sorry for chiming here again, just one question here for my learning, since you worked on making the tracking done on a background thread before (#11293), what's the usefulness of making this suspendable?
I believe we should build things based on the API, not the current implementation. Eventually, if all goes well we may use another implementation of the tracking itself, which may or may not be implemented in a blocking manner, so having this suspended in the first place is a good idea in my mind
I think a more appropriate dispatcher to use would be Dispatchers.Default, Dispatchers.IO is destined more for blocking IO operations, which is not the case here
Tracking it's a network call - why Default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, if all goes well we may use another implementation of the tracking itself, which may or may not be implemented in a blocking manner, so having this suspended in the first place is a good idea in my mind
I would have agreed with this if the call was going to an external dependency, but in this case, it goes to our AnalyticsTracker
class, which internally keeps a queue and handles the events, then these events are also emitted to another queue in Tracks
library (which is also our internal library), I feel like we are overengineering this part 🙂, and with the complexity, we increase the change of any other issues:
- Ordering (that we discussed on the other PR), I think it would be a major issue here given the parallelism involved with using
Dispatchers.IO
. - Non-accurate timestamps.
- Other stuff that we didn't think of.
Tracking it's a network call - why Default?
I don't think we can consider Tracking as a network call, we are just saving the items to an in-memory queue, the networking part is handled using a dedicate Thread in the Tracks
library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further discussion on Slack.
Closes: #11517
Description
The PR:
woocommerceandroid_pos_
to POS eventsTesting instructions
Use tracks live view to do so
Images/gif
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.