From f0562ad65f807120f4df667df07c1db2e4e5adab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Wed, 9 Nov 2022 11:26:31 -0500 Subject: [PATCH] Adds a templateElegible property to productListAddProductTapped event --- .../Classes/Analytics/WooAnalyticsEvent.swift | 5 +++++ .../Add Product/AddProductCoordinator.swift | 13 +++++++++++-- .../Products/ProductsViewController.swift | 2 -- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift b/WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift index 4ff6b27ba41..ff8260e4574 100644 --- a/WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift +++ b/WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift @@ -1722,6 +1722,7 @@ extension WooAnalyticsEvent { enum ProductsOnboarding { enum Keys: String { case type + case templateEligible = "template_eligible" } enum CreationType: String { @@ -1746,5 +1747,9 @@ extension WooAnalyticsEvent { static func productCreationTypeSelected(type: CreationType) -> WooAnalyticsEvent { WooAnalyticsEvent(statName: .addProductCreationTypeSelected, properties: [Keys.type.rawValue: type.rawValue]) } + + static func productListAddProductButtonTapped(templateEligible: Bool) -> WooAnalyticsEvent { + WooAnalyticsEvent(statName: .productListAddProductTapped, properties: [Keys.templateEligible.rawValue: templateEligible]) + } } } diff --git a/WooCommerce/Classes/ViewRelated/Products/Add Product/AddProductCoordinator.swift b/WooCommerce/Classes/ViewRelated/Products/Add Product/AddProductCoordinator.swift index fce06e70675..19609695735 100644 --- a/WooCommerce/Classes/ViewRelated/Products/Add Product/AddProductCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/Products/Add Product/AddProductCoordinator.swift @@ -65,6 +65,9 @@ final class AddProductCoordinator: Coordinator { } func start() { + + ServiceLocator.analytics.track(event: .ProductsOnboarding.productListAddProductButtonTapped(templateEligible: isTemplateOptionsEligible())) + if shouldPresentProductCreationBottomSheet() { presentProductCreationTypeBottomSheet() } else { @@ -77,10 +80,16 @@ final class AddProductCoordinator: Coordinator { private extension AddProductCoordinator { /// Defines if the product creation bottom sheet should be presented. - /// Currently returns `true` when the feature is enabled and the number of products is fewer than 3. + /// Currently returns `true` when the feature is enabled and the store is eligible for displaying template options. /// func shouldPresentProductCreationBottomSheet() -> Bool { - isProductCreationTypeEnabled && productsResultsController.numberOfObjects < 3 + isProductCreationTypeEnabled && isTemplateOptionsEligible() + } + + /// Returns `true` when the number of products is fewer than 3. + /// + func isTemplateOptionsEligible() -> Bool { + productsResultsController.numberOfObjects < 3 } /// Presents a bottom sheet for users to choose if they want a create a product manually or via a template. diff --git a/WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift b/WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift index 9b06f1eb936..e1eb0e653af 100644 --- a/WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift @@ -258,8 +258,6 @@ private extension ProductsViewController { return } - ServiceLocator.analytics.track(.productListAddProductTapped) - let coordinatingController: AddProductCoordinator if let sourceBarButtonItem = sourceBarButtonItem { coordinatingController = AddProductCoordinator(siteID: siteID,