Skip to content

Commit

Permalink
Merge pull request #12257 from woocommerce/issue/fix-google-analytics…
Browse files Browse the repository at this point in the history
…-cta-placement

[Wear App] Fix Google Analytics CTA placement in Analytics Hub
  • Loading branch information
ThomazFB authored Aug 8, 2024
2 parents 3515320 + b300df2 commit a39e271
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,23 @@ sealed class AnalyticsHubCustomSelectionListViewState : AnalyticsCardViewState {
}
}

data class HiddenState(
override val card: AnalyticsCards
) : AnalyticsHubCustomSelectionListViewState()
data class ShowCTAState(
override val card: AnalyticsCards,
val title: String,
val description: String,
val callToActionText: String,
val isVisible: Boolean,
val onCallToActionClickListener: () -> Unit
) : AnalyticsHubCustomSelectionListViewState() {
val asAnalyticsHubUserCallToActionViewState
get() = AnalyticsHubUserCallToActionViewState(
title = title,
description = description,
callToActionText = callToActionText,
isVisible = isVisible,
onCallToActionClickListener = onCallToActionClickListener
)
}
}

data class AnalyticsHubUserCallToActionViewState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class AnalyticsHubFragment : BaseFragment(R.layout.fragment_analytics) {
binding.analyticsDateSelectorCard.updatePreviousRange(viewState.analyticsDateRangeSelectorState.previousRange)
binding.analyticsDateSelectorCard.updateCurrentRange(viewState.analyticsDateRangeSelectorState.currentRange)
binding.analyticsDateSelectorCard.updateLastUpdateTimestamp(viewState.lastUpdateTimestamp)
binding.analyticsCallToActionCard.updateInformation(viewState.ctaState)
binding.analyticsRefreshLayout.isRefreshing = viewState.refreshIndicator == ShowIndicator
displayFeedbackBanner(viewState.showFeedBackBanner)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import com.woocommerce.android.model.SessionStat
import com.woocommerce.android.model.StatType
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.CustomListViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.HiddenState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.LoadingAdsViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.ShowCTAState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubInformationViewState.DataViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubInformationViewState.LoadingViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubInformationViewState.NoDataState
Expand Down Expand Up @@ -118,7 +118,6 @@ class AnalyticsHubViewModel @Inject constructor(
refreshIndicator = NotShowIndicator,
analyticsDateRangeSelectorState = AnalyticsHubDateRangeSelectorViewState.EMPTY,
cards = AnalyticsHubCardViewState.LoadingCardsConfiguration,
ctaState = AnalyticsHubUserCallToActionViewState.EMPTY,
showFeedBackBanner = false,
lastUpdateTimestamp = ""
)
Expand Down Expand Up @@ -486,16 +485,19 @@ class AnalyticsHubViewModel @Inject constructor(

private fun observeGoogleAdsChanges() {
googleAdsObservationJob = updateStats.googleAdsState.onEach { state ->
updateGoogleAdsCTAVisibility(isVisible = false)

when (state) {
is GoogleAdsState.Available -> {
updateCardStatus(AnalyticsCards.GoogleAds, buildGoogleAdsDataViewState(state.googleAdsStat))
}

is GoogleAdsState.Empty -> {
updateGoogleAdsCTAVisibility(isVisible = true)
updateCardStatus(AnalyticsCards.GoogleAds, HiddenState(AnalyticsCards.GoogleAds))
tracker.track(
stat = AnalyticsEvent.GOOGLEADS_ENTRY_POINT_DISPLAYED,
properties = mapOf(
KEY_GOOGLEADS_SOURCE to VALUE_GOOGLEADS_ENTRY_POINT_TYPE_ANALYTICS_HUB
)
)
updateCardStatus(AnalyticsCards.GoogleAds, buildGoogleAdsCTAViewState())
}

is GoogleAdsState.Error -> {
Expand Down Expand Up @@ -742,6 +744,17 @@ class AnalyticsHubViewModel @Inject constructor(
)
}

private fun buildGoogleAdsCTAViewState(): ShowCTAState {
return ShowCTAState(
card = AnalyticsCards.GoogleAds,
title = resourceProvider.getString(R.string.analytics_google_ads_cta_title),
description = resourceProvider.getString(R.string.analytics_google_ads_cta_description),
callToActionText = resourceProvider.getString(R.string.analytics_google_ads_cta_action),
isVisible = true,
onCallToActionClickListener = { onGoogleAdsCTAClicked() }
)
}

private fun onGoogleCampaignFilterSelected(
googleAdsStats: GoogleAdsStat,
selectedFilterName: String
Expand Down Expand Up @@ -823,27 +836,6 @@ class AnalyticsHubViewModel @Inject constructor(
giftCardsObservationJob?.cancel()
}

private fun updateGoogleAdsCTAVisibility(isVisible: Boolean) {
AnalyticsHubUserCallToActionViewState(
title = resourceProvider.getString(R.string.analytics_google_ads_cta_title),
description = resourceProvider.getString(R.string.analytics_google_ads_cta_description),
callToActionText = resourceProvider.getString(R.string.analytics_google_ads_cta_action),
isVisible = isVisible,
onCallToActionClickListener = { onGoogleAdsCTAClicked() }
).let { newState ->
mutableState.update { it.copy(ctaState = newState) }
}

if (isVisible) {
tracker.track(
stat = AnalyticsEvent.GOOGLEADS_ENTRY_POINT_DISPLAYED,
properties = mapOf(
KEY_GOOGLEADS_SOURCE to VALUE_GOOGLEADS_ENTRY_POINT_TYPE_ANALYTICS_HUB
)
)
}
}

private fun onGoogleAdsCTAClicked() {
selectedSite.getOrNull()?.let {
it.adminUrlOrDefault + GOOGLE_ADMIN_CAMPAIGN_CREATION_SUFFIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ data class AnalyticsViewState(
val refreshIndicator: RefreshIndicator,
val analyticsDateRangeSelectorState: AnalyticsHubDateRangeSelectorViewState,
val cards: AnalyticsHubCardViewState,
val ctaState: AnalyticsHubUserCallToActionViewState,
val showFeedBackBanner: Boolean,
val lastUpdateTimestamp: String
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import com.woocommerce.android.R
import com.woocommerce.android.databinding.AnalyticsCustomSelectionCardViewBinding
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.CustomListViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.HiddenState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.LoadingAdsViewState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.NoAdsState
import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.ShowCTAState
import com.woocommerce.android.ui.analytics.hub.informationcard.SeeReportClickListener
import com.woocommerce.android.ui.analytics.hub.listcard.AnalyticsHubListAdapter
import com.woocommerce.android.ui.analytics.hub.listcard.AnalyticsHubListCardView
Expand All @@ -37,13 +37,15 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor(
is LoadingAdsViewState -> setSkeleton()
is NoAdsState -> setNoAdsViewState(viewState)
is CustomListViewState -> setDataViewState(viewState)
is HiddenState -> setHiddenState()
is ShowCTAState -> setCtaState(viewState)
}
}

private fun setHiddenState() {
private fun setCtaState(state: ShowCTAState) {
skeletonView.hide()
binding.analyticsCustomCardListContainer.visibility = GONE
binding.analyticsCallToActionCard.visibility = VISIBLE
binding.analyticsCallToActionCard.updateInformation(state.asAnalyticsHubUserCallToActionViewState)
}

private fun setDataViewState(viewState: CustomListViewState) {
Expand Down Expand Up @@ -78,6 +80,7 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor(
binding.analyticsListLeftHeader.visibility = VISIBLE
binding.analyticsListRightHeader.visibility = VISIBLE
binding.noDataText.visibility = GONE
binding.analyticsCallToActionCard.visibility = GONE

viewState.reportUrl?.let {
binding.reportGroup.visibility = VISIBLE
Expand Down Expand Up @@ -121,6 +124,7 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor(
binding.analyticsListRightHeader.visibility = GONE
binding.analyticsItemsTag.visibility = GONE
binding.analyticsFilterButton.visibility = GONE
binding.analyticsCallToActionCard.visibility = GONE
binding.noDataText.visibility = VISIBLE
binding.noDataText.text = viewState.message
}
Expand All @@ -140,6 +144,7 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor(
binding.analyticsItemsTag.visibility = GONE
binding.noDataText.visibility = GONE
binding.analyticsFilterButton.visibility = GONE
binding.analyticsCallToActionCard.visibility = GONE
}

private fun getDeltaTagText(viewState: CustomListViewState) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:id="@+id/analyticsCallToActionCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/major_75"
android:layout_marginVertical="@dimen/major_75"
android:orientation="vertical">

<com.google.android.material.textview.MaterialTextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
android:layout_height="wrap_content"
tools:context=".ui.analytics.hub.customlistcard.AnalyticsHubCustomSelectionCardView">

<com.woocommerce.android.ui.analytics.hub.cta.AnalyticsHubUserCallToActionView
android:id="@+id/analyticsCallToActionCard"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/analyticsCustomCardListContainer"
android:layout_width="match_parent"
Expand Down
11 changes: 1 addition & 10 deletions WooCommerce/src/main/res/layout/fragment_analytics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider" />

<com.woocommerce.android.ui.analytics.hub.cta.AnalyticsHubUserCallToActionView
android:id="@+id/analyticsCallToActionCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/major_100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/analyticsDateSelectorCard" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cards"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/major_100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/analyticsCallToActionCard" />
app:layout_constraintTop_toBottomOf="@+id/analyticsDateSelectorCard" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down

0 comments on commit a39e271

Please sign in to comment.