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

[Woo POS] Tracking preparaion #11537

Merged
merged 11 commits into from
May 30, 2024

Conversation

kidinov
Copy link
Contributor

@kidinov kidinov commented May 17, 2024

Closes: #11517

Description

The PR:

  • Decouple current tracking logic from the POS, but reusing that
  • Adds woocommerceandroid_pos_ to POS events
  • Makes tracking more safe and enforces us to do it without blocking the UI

Testing instructions

  • Use the app and notice that there are no changes in tracking for the current screens
  • Use the POS screen and navigate to the checkout screen -> notice test event tracked with new prefix

Use tracks live view to do so

Images/gif

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@kidinov kidinov linked an issue May 17, 2024 that may be closed by this pull request
@dangermattic
Copy link
Collaborator

dangermattic commented May 17, 2024

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ This PR is assigned to the milestone 18.9. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.
1 Message
📖

This PR contains changes to Tracks-related logic. Please ensure (author and reviewer) the following are completed:

  • The tracks events must be validated in the Tracks system.
  • Verify the internal Tracks spreadsheet has also been updated.
  • Please consider registering any new events.
  • The PR must be assigned the category: tracks label.

Generated by 🚫 Danger

@kidinov kidinov marked this pull request as draft May 17, 2024 14:27
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 17, 2024

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
FlavorJalapeno
Build TypeDebug
Commitefd04a8
Direct Downloadwoocommerce-prototype-build-pr11537-efd04a8.apk

@codecov-commenter
Copy link

codecov-commenter commented May 17, 2024

Codecov Report

Attention: Patch coverage is 38.52097% with 557 lines in your changes are missing coverage. Please review.

Project coverage is 39.39%. Comparing base (50cd183) to head (efd04a8).

Files Patch % Lines
...om/woocommerce/android/analytics/AnalyticsEvent.kt 36.54% 540 Missing ⚠️
...roid/ui/woopos/checkout/WooPosCheckoutViewModel.kt 0.00% 7 Missing ⚠️
...ui/woopos/util/analytics/WooPosAnalyticsTracker.kt 80.00% 2 Missing and 2 partials ⚠️
.../woocommerce/android/analytics/AnalyticsTracker.kt 25.00% 3 Missing ⚠️
...alytics/WooPosAnalyticsCommonPropertiesProvider.kt 0.00% 2 Missing ⚠️
...ndroid/ui/woopos/util/analytics/WooPosAnalytics.kt 95.23% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@kidinov kidinov added the category: tracks Related to analytics, including Tracks Events. label May 21, 2024
@kidinov kidinov added this to the 18.8 milestone May 21, 2024
@@ -1,1057 +1,1066 @@
package com.woocommerce.android.analytics

enum class AnalyticsEvent(val siteless: Boolean = false) {
interface IAnalyticsEvent {
Copy link
Contributor Author

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*

Copy link
Contributor

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

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

Copy link
Contributor

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

Choose a reason for hiding this comment

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

@backwardstruck @samiuelson

Shell we actually reuse ScopedViewModel? That couples us to the main code but gives some reduction in the complexity of the POS. wdyt?

Copy link
Contributor

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.

Copy link
Contributor Author

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? =)

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samiuelson @backwardstruck

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

#11622

@kidinov kidinov marked this pull request as ready for review May 21, 2024 11:13
@backwardstruck backwardstruck self-assigned this May 21, 2024
Copy link
Contributor

@backwardstruck backwardstruck left a comment

Choose a reason for hiding this comment

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

Code changes look good. I see the event on Tracks live as well. Feel free to merge once other feedback is in and the test event is removed:

Screenshot 2024-05-21 at 16 32 31

@backwardstruck backwardstruck modified the milestones: 18.8, 18.9 May 24, 2024
# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/analytics/AnalyticsEvent.kt
@samiuelson samiuelson self-assigned this May 29, 2024
Copy link
Collaborator

@samiuelson samiuelson left a 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!

@kidinov kidinov merged commit 9f3dd6e into trunk May 30, 2024
14 checks passed
@kidinov kidinov deleted the 11517-woo-pos-prepare-tracking-with-pos-prefix branch May 30, 2024 10:01
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper,
private val commonPropertiesProvider: WooPosAnalyticsCommonPropertiesProvider
) {
suspend fun track(analytics: IAnalyticsEvent) {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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:

  1. 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.
  2. Non-accurate timestamps.
  3. 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Further discussion on Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tracks Related to analytics, including Tracks Events.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Woo POS] Prepare tracking with POS prefix
7 participants