Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sealed class LayoutPickerUiState(
override val isToolbarVisible: Boolean = false,
val selectedCategoriesSlugs: ArrayList<String> = arrayListOf(),
val selectedLayoutSlug: String? = null,
val isSelectedLayoutRecommended: Boolean = false,
val loadedThumbnailSlugs: ArrayList<String> = arrayListOf(),
val categories: List<CategoryListItemUiState> = listOf(),
val layoutCategories: List<LayoutCategoryUiState> = listOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ abstract class LayoutPickerViewModel(
mShotPreview = thumbnailPreview,
selected = layout.slug == state.selectedLayoutSlug,
tapOpensPreview = thumbnailTapOpensPreview,
onItemTapped = { onLayoutTapped(layoutSlug = layout.slug) },
onItemTapped = { onLayoutTapped(layoutSlug = layout.slug, category.isRecommended) },
onThumbnailReady = { onThumbnailReady(layoutSlug = layout.slug) }
)
}
Expand All @@ -194,7 +194,7 @@ abstract class LayoutPickerViewModel(
* Layout tapped
* @param layoutSlug the slug of the tapped layout
*/
open fun onLayoutTapped(layoutSlug: String) {
open fun onLayoutTapped(layoutSlug: String, isRecommended: Boolean = false) {
(uiState.value as? Content)?.let { state ->
if (!state.loadedThumbnailSlugs.contains(layoutSlug)) return // No action
if (layoutSlug == state.selectedLayoutSlug) { // deselect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.C
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.FILTER
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.LOCATION
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.PREVIEW_MODE
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.RECOMMENDED
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.SEARCH_TERM
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.SEGMENT_ID
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker.PROPERTY.SEGMENT_NAME
Expand Down Expand Up @@ -47,7 +48,8 @@ class SiteCreationTracker @Inject constructor(val tracker: AnalyticsTrackerWrapp
SELECTED_FILTERS("selected_filters"),
VERTICAL_SLUG("vertical_slug"),
VARIATION("variation"),
SITE_NAME("site_name")
SITE_NAME("site_name"),
RECOMMENDED("recommended")
}

private var designSelectionSkipped: Boolean = false
Expand Down Expand Up @@ -172,11 +174,11 @@ class SiteCreationTracker @Inject constructor(val tracker: AnalyticsTrackerWrapp
tracker.track(AnalyticsTracker.Stat.ENHANCED_SITE_CREATION_SITE_DESIGN_SKIPPED)
}

fun trackSiteDesignSelected(template: String) {
fun trackSiteDesignSelected(template: String, recommended: Boolean) {
designSelectionSkipped = false
tracker.track(
AnalyticsTracker.Stat.ENHANCED_SITE_CREATION_SITE_DESIGN_SELECTED,
mapOf(TEMPLATE.key to template)
mapOf(TEMPLATE.key to template, RECOMMENDED.key to recommended)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class HomePagePickerViewModel @Inject constructor(
}
}

override fun onLayoutTapped(layoutSlug: String) {
override fun onLayoutTapped(layoutSlug: String, isRecommended: Boolean) {
(uiState.value as? Content)?.let {
if (it.loadedThumbnailSlugs.contains(layoutSlug)) {
updateUiState(it.copy(selectedLayoutSlug = layoutSlug))
updateUiState(it.copy(selectedLayoutSlug = layoutSlug, isSelectedLayoutRecommended = isRecommended))
onPreviewTapped()
loadLayouts()
}
Expand All @@ -112,7 +112,8 @@ class HomePagePickerViewModel @Inject constructor(
selectedLayout?.let { layout ->
super.onPreviewChooseTapped()
val template = layout.slug
analyticsTracker.trackSiteDesignSelected(template)
val isRecommended = (uiState.value as? Content)?.isSelectedLayoutRecommended == true
analyticsTracker.trackSiteDesignSelected(template, isRecommended)
_onDesignActionPressed.value = DesignSelectionAction.Choose(template)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,22 @@ class HomePagePickerViewModelTest {
verify(onDesignActionObserver).onChanged(captor.capture())
assertThat(captor.value.template).isEqualTo(mockedDesignSlug)
}

@Test
fun `when the user chooses a recommended design the recommended information is emitted`() = mockResponse {
viewModel.start()
viewModel.onThumbnailReady(mockedDesignSlug)
viewModel.onLayoutTapped(mockedDesignSlug, true)
viewModel.onPreviewChooseTapped()
verify(analyticsTracker).trackSiteDesignSelected(mockedDesignSlug, true)
}

@Test
fun `when the user chooses a design that is not recommended the correct information is emitted`() = mockResponse {
viewModel.start()
viewModel.onThumbnailReady(mockedDesignSlug)
viewModel.onLayoutTapped(mockedDesignSlug, false)
viewModel.onPreviewChooseTapped()
verify(analyticsTracker).trackSiteDesignSelected(mockedDesignSlug, false)
}
}