Skip to content

Commit 5e67a0c

Browse files
authored
Merge pull request #8011 from woocommerce/issue/7923-add-template-analytics
Products Onboarding: Template Analytics
2 parents e2e4a4b + 0aaf035 commit 5e67a0c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,15 @@ extension WooAnalyticsEvent {
16891689
//
16901690
extension WooAnalyticsEvent {
16911691
enum ProductsOnboarding {
1692+
enum Keys: String {
1693+
case type
1694+
}
1695+
1696+
enum CreationType: String {
1697+
case manual
1698+
case template
1699+
}
1700+
16921701
/// Tracks when a store is eligible for products onboarding
16931702
///
16941703
static func storeIsEligible() -> WooAnalyticsEvent {
@@ -1700,5 +1709,11 @@ extension WooAnalyticsEvent {
17001709
static func bannerCTATapped() -> WooAnalyticsEvent {
17011710
WooAnalyticsEvent(statName: .productsOnboardingCTATapped, properties: [:])
17021711
}
1712+
1713+
/// Trackas when the merchants selects a product creation type.
1714+
///
1715+
static func productCreationTypeSelected(type: CreationType) -> WooAnalyticsEvent {
1716+
WooAnalyticsEvent(statName: .addProductCreationTypeSelected, properties: [Keys.type.rawValue: type.rawValue])
1717+
}
17031718
}
17041719
}

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ public enum WooAnalyticsStat: String {
424424

425425
// MARK: Add Product Events
426426
//
427+
case addProductCreationTypeSelected = "add_product_creation_type_selected"
427428
case addProductTypeSelected = "add_product_product_type_selected"
428429
case addProductPublishTapped = "add_product_publish_tapped"
429430
case addProductSaveAsDraftTapped = "add_product_save_as_draft_tapped"

WooCommerce/Classes/ViewRelated/Products/Add Product/AddProductCoordinator.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private extension AddProductCoordinator {
8989
comment: "Message title of bottom sheet for selecting a template or manual product")
9090
let viewProperties = BottomSheetListSelectorViewProperties(title: title)
9191
let command = ProductCreationTypeSelectorCommand { selectedCreationType in
92-
// TODO: Add analytics
92+
self.trackProductCreationType(selectedCreationType)
9393
self.presentProductTypeBottomSheet(creationType: selectedCreationType)
9494
}
9595
let productTypesListPresenter = BottomSheetListSelectorPresenter(viewProperties: viewProperties, command: command)
@@ -225,9 +225,23 @@ private extension AddProductCoordinator {
225225

226226
/// Presents an general error notice using the system notice presenter.
227227
///
228-
private func presentErrorNotice() {
228+
func presentErrorNotice() {
229229
let notice = Notice(title: NSLocalizedString("There was a problem creating the template product.",
230230
comment: "Title for the error notice when creating a template product"))
231231
ServiceLocator.noticePresenter.enqueue(notice: notice)
232232
}
233+
234+
/// Tracks the selected product creation type.
235+
///
236+
func trackProductCreationType(_ type: ProductCreationType) {
237+
let analyticsType: WooAnalyticsEvent.ProductsOnboarding.CreationType = {
238+
switch type {
239+
case .template:
240+
return .template
241+
case .manual:
242+
return .manual
243+
}
244+
}()
245+
ServiceLocator.analytics.track(event: .ProductsOnboarding.productCreationTypeSelected(type: analyticsType))
246+
}
233247
}

0 commit comments

Comments
 (0)