Skip to content

Commit

Permalink
+ Adds: the logic to track site items on self hosted site
Browse files Browse the repository at this point in the history
  • Loading branch information
AjeshRPai committed Feb 11, 2024
1 parent 0e74d16 commit 31d68d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import org.wordpress.android.ui.mysite.MySiteUiState.PartialState
import org.wordpress.android.ui.mysite.MySiteViewModel.State.NoSites
import org.wordpress.android.ui.mysite.MySiteViewModel.State.SiteSelected
import org.wordpress.android.ui.mysite.cards.DashboardCardsViewModelSlice
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker
import org.wordpress.android.ui.mysite.cards.jetpackfeature.JetpackFeatureCardShownTracker
import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository
import org.wordpress.android.ui.mysite.cards.siteinfo.SiteInfoHeaderCardViewModelSlice
import org.wordpress.android.ui.mysite.items.DashboardItemsViewModelSlice
Expand Down Expand Up @@ -77,12 +75,10 @@ class MySiteViewModel @Inject constructor(
private val quickStartUtilsWrapper: QuickStartUtilsWrapper,
private val snackbarSequencer: SnackbarSequencer,
private val landOnTheEditorFeatureConfig: LandOnTheEditorFeatureConfig,
private val cardsTracker: CardsTracker,
private val buildConfigWrapper: BuildConfigWrapper,
private val appPrefsWrapper: AppPrefsWrapper,
private val quickStartTracker: QuickStartTracker,
private val dispatcher: Dispatcher,
private val jetpackFeatureCardShownTracker: JetpackFeatureCardShownTracker,
private val jetpackFeatureRemovalUtils: JetpackFeatureRemovalOverlayUtil,
private val getShowJetpackFullPluginInstallOnboardingUseCase: GetShowJetpackFullPluginInstallOnboardingUseCase,
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper,
Expand Down Expand Up @@ -259,7 +255,6 @@ class MySiteViewModel @Inject constructor(
}

fun onResume() {
// mySiteSourceManager.onResume(isSiteSelected)
isSiteSelected = false
checkAndShowJetpackFullPluginInstallOnboarding()
checkAndShowQuickStartNotice()
Expand Down Expand Up @@ -471,10 +466,6 @@ class MySiteViewModel @Inject constructor(
}
}

private fun onDashboardErrorRetry() {
// mySiteSourceManager.refresh()
}

fun onActionableEmptyViewVisible() {
analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_DISPLAYED)
checkJetpackIndividualPluginOverlayShouldShow()
Expand All @@ -497,19 +488,6 @@ class MySiteViewModel @Inject constructor(
_onNavigation.postValue(Event(BloggingPromptCardNavigationAction.LearnMore))
}

private fun trackCardsAndItemsShownIfNeeded() {
// siteSelected.dashboardData.filterIsInstance<JetpackFeatureCard>()
// .forEach { jetpackFeatureCardShownTracker.trackShown(it.type) }
//// siteSelected.dashboardData.filterIsInstance<MySiteCardAndItem.Card.WpSotw2023NudgeCardModel>()
//// .forEach { _ -> sotw2023NudgeCardViewModelSlice.trackShown() }
}

private fun resetShownTrackers() {
cardsTracker.resetShown()
jetpackFeatureCardShownTracker.resetShown()
dashboardCardsViewModelSlice.resetShownTracker()
// sotw2023NudgeCardViewModelSlice.resetShown()
}

// FluxC events
@Subscribe(threadMode = MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.distinctUntilChanged
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import org.wordpress.android.fluxc.model.SiteModel
Expand All @@ -30,6 +31,8 @@ class DashboardItemsViewModelSlice @Inject constructor(
) {
private lateinit var scope: CoroutineScope

private var trackingJob : Job? = null

fun initialize(scope: CoroutineScope) {
this.scope = scope
sotw2023NudgeCardViewModelSlice.initialize(scope)
Expand Down Expand Up @@ -80,6 +83,7 @@ class DashboardItemsViewModelSlice @Inject constructor(
else jetpackFeatureCard?.let { add(jetpackFeatureCard) }
jetpackBadge?.let { add(jetpackBadge) }
}.toList()
trackShown(dasbhboardSiteItems)
return dasbhboardSiteItems
}

Expand All @@ -101,7 +105,26 @@ class DashboardItemsViewModelSlice @Inject constructor(
sotw2023NudgeCardViewModelSlice.clearValue()
}

fun resetShownTracker() {
trackingJob?.cancel()
sotw2023NudgeCardViewModelSlice.resetShown()
jetpackFeatureCardViewModelSlice.resetShown()
}

fun trackShown(dasbhboardSiteItems: MutableList<MySiteCardAndItem>) = with(dasbhboardSiteItems) {
trackingJob?.cancel()
trackingJob = scope.launch {
filterIsInstance<MySiteCardAndItem.Card.JetpackFeatureCard>().forEach {
jetpackFeatureCardViewModelSlice.trackShown(it.type)
}
filterIsInstance<MySiteCardAndItem.Card.WpSotw2023NudgeCardModel>().forEach {
sotw2023NudgeCardViewModelSlice.trackShown()
}
}
}

fun onCleared() {
trackingJob?.cancel()
scope.cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil
import org.wordpress.android.ui.mysite.MySiteCardAndItem
import org.wordpress.android.ui.mysite.SiteNavigationAction
import org.wordpress.android.ui.mysite.cards.jetpackfeature.JetpackFeatureCardHelper
import org.wordpress.android.ui.mysite.cards.jetpackfeature.JetpackFeatureCardShownTracker
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.viewmodel.Event
import javax.inject.Inject

class JetpackFeatureCardViewModelSlice @Inject constructor(
private val jetpackFeatureCardHelper: JetpackFeatureCardHelper,
private val jetpackFeatureCardShownTracker: JetpackFeatureCardShownTracker
) {
private val _onNavigation = MutableLiveData<Event<SiteNavigationAction>>()
val onNavigation = _onNavigation
Expand Down Expand Up @@ -74,5 +76,13 @@ class JetpackFeatureCardViewModelSlice @Inject constructor(
fun clearValue() {
_uiModel.postValue(null)
}

fun trackShown(itemType: MySiteCardAndItem.Type) {
jetpackFeatureCardShownTracker.trackShown(itemType)
}

fun resetShown() {
jetpackFeatureCardShownTracker.resetShown()
}
}

0 comments on commit 31d68d7

Please sign in to comment.