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

Adds tracking to site visibility editing #13223

Open
wants to merge 7 commits into
base: issue/13213-disable-notifications-api-request
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ enum class AnalyticsEvent(override val siteless: Boolean = false) : IAnalyticsEv
SITE_PICKER_SITE_DISCOVERY(siteless = true),
SITE_PICKER_JETPACK_TIMEOUT_ERROR_SHOWN(siteless = true),
SITE_PICKER_JETPACK_TIMEOUT_CONTACT_SUPPORT_CLICKED(siteless = true),
SITE_PICKER_EDIT_BUTTON_SHOWN(siteless = true),
SITE_PICKER_EDIT_BUTTON_TAPPED(siteless = true),
SITE_PICKER_LIST_SAVE_BUTTON_TAPPED(siteless = true),
SITE_PICKER_LIST_SAVING_SUCCESS(siteless = true),
SITE_PICKER_LIST_SAVING_FAILURE(siteless = true),

// -- Jetpack Installation for Login
LOGIN_JETPACK_SITE_CREDENTIAL_SCREEN_VIEWED(siteless = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.woocommerce.android.NavGraphMainDirections
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.databinding.FragmentSitePickerBinding
import com.woocommerce.android.extensions.handleNotice
import com.woocommerce.android.extensions.handleResult
Expand Down Expand Up @@ -76,6 +77,9 @@ class SitePickerFragment :
@Inject
lateinit var uiMessageResolver: UIMessageResolver

@Inject
lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper

private var skeletonView = SkeletonView()
private var progressDialog: CustomProgressDialog? = null

Expand Down Expand Up @@ -117,6 +121,7 @@ class SitePickerFragment :
}

R.id.menu_edit_store_list -> {
analyticsTrackerWrapper.track(stat = AnalyticsEvent.SITE_PICKER_EDIT_BUTTON_TAPPED)
findNavController().navigateSafely(
SitePickerFragmentDirections.actionSitePickerFragmentToStoreVisibilityFragment()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,17 @@ class SitePickerViewModel @Inject constructor(
val selectedSiteId = selectedSiteId.value ?: wooSites.getOrNull(0)?.id
_sites.value = buildSitesList(wooSites, selectedSiteId, nonWooSites)

val isEditListEnabled = FeatureFlag.HIDE_SITES_FROM_SITE_PICKER.isEnabled() && wooSites.size > 1
if (isEditListEnabled && sitePickerViewState.editStoreListEnabled.not()) {
analyticsTrackerWrapper.track(stat = AnalyticsEvent.SITE_PICKER_EDIT_BUTTON_SHOWN)
}

sitePickerViewState = sitePickerViewState.copy(
hasConnectedStores = sites.isNotEmpty(),
isPrimaryBtnVisible = wooSites.isNotEmpty(),
isNoStoresViewVisible = false,
currentSitePickerState = SitePickerState.StoreListState,
editStoreListEnabled = FeatureFlag.HIDE_SITES_FROM_SITE_PICKER.isEnabled() && wooSites.size > 1
editStoreListEnabled = isEditListEnabled
)
loginSiteAddress?.let {
processLoginSiteAddress(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.woocommerce.android.ui.sitepicker.sitevisibility
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.asLiveData
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_ERROR
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.ui.sitepicker.SitePickerRepository
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event
Expand All @@ -15,6 +18,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.store.NotificationStore
import org.wordpress.android.fluxc.store.NotificationStore.NotificationSettingsUpdateError
import org.wordpress.android.fluxc.store.NotificationStore.SiteNotificationSetting
import javax.inject.Inject

Expand All @@ -24,6 +28,7 @@ class WooSitesVisibilityViewModel @Inject constructor(
private val selectedSite: SelectedSite,
private val visibleSitesDataStore: VisibleWooSitesDataStore,
private val notificationsStore: NotificationStore,
private val trackerWrapper: AnalyticsTrackerWrapper,
savedStateHandle: SavedStateHandle
) : ScopedViewModel(savedStateHandle) {
private var initiallySelectedSiteIds: List<Long> = emptyList()
Expand Down Expand Up @@ -55,6 +60,12 @@ class WooSitesVisibilityViewModel @Inject constructor(
}

fun onSaveTapped() {
trackerWrapper.track(
stat = AnalyticsEvent.SITE_PICKER_LIST_SAVE_BUTTON_TAPPED,
properties = mapOf(
"hidden_site_count" to _wooStoresState.value.wooStores.count { !it.isSelected }
)
)
_wooStoresState.value = _wooStoresState.value.copy(isLoading = true)
launch {
notificationsStore.updateNotificationSettingsFor(
Expand All @@ -67,13 +78,20 @@ class WooSitesVisibilityViewModel @Inject constructor(
}
).fold(
onSuccess = {
trackerWrapper.track(stat = AnalyticsEvent.SITE_PICKER_LIST_SAVING_SUCCESS)
visibleSitesDataStore.updateSiteVisibilityStatus(
_wooStoresState.value.wooStores
.associate { it.siteId to it.isSelected }
)
triggerEvent(ExitWithResult(data = true))
},
onFailure = {
if (it is NotificationSettingsUpdateError) {
trackerWrapper.track(
stat = AnalyticsEvent.SITE_PICKER_LIST_SAVING_FAILURE,
properties = mapOf(KEY_ERROR to it.type.toString())
)
}
triggerEvent(
Event.ShowDialog(
titleId = R.string.site_picker_edit_store_list_error_title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.woocommerce.android.ui.sitepicker.sitevisibility

import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.ui.sitepicker.SitePickerRepository
import com.woocommerce.android.ui.sitepicker.SitePickerTestUtils
Expand Down Expand Up @@ -66,6 +67,7 @@ class WooSitesVisibilityViewModelTest : BaseUnitTest() {
private val visibleWooSitesDataStore: VisibleWooSitesDataStore = mock {
onBlocking { isSiteVisible(any()) } doReturn flowOf(true)
}
private val trackerWrapper: AnalyticsTrackerWrapper = mock()

private val notificationStore: NotificationStore = mock()

Expand All @@ -78,6 +80,7 @@ class WooSitesVisibilityViewModelTest : BaseUnitTest() {
selectedSite = selectedSite,
visibleSitesDataStore = visibleWooSitesDataStore,
notificationsStore = notificationStore,
trackerWrapper = trackerWrapper,
savedStateHandle = mock()
)
}
Expand Down
Loading