Skip to content

Commit 124ece6

Browse files
authored
Merge pull request #5877 from woocommerce/issue/5798-Hub-Menu-Tracking-Events
Implemented tracking events for the Hub Menu
2 parents 298a54b + dab5da8 commit 124ece6

File tree

5 files changed

+49
-32
lines changed

5 files changed

+49
-32
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,14 @@ public enum WooAnalyticsStat: String {
550550
case jetpackInstallFailed = "jetpack_install_failed"
551551
case jetpackInstallInWPAdminButtonTapped = "jetpack_install_in_wpadmin_button_tapped"
552552
case jetpackInstallContactSupportButtonTapped = "jetpack_install_contact_support_button_tapped"
553+
554+
// MARK: Hub Menu
555+
//
556+
case hubMenuTabSelected = "hub_menu_tab_selected"
557+
case hubMenuTabReselected = "hub_menu_tab_reselected"
558+
case hubMenuSwitchStoreTapped = "hub_menu_switch_store_tapped"
559+
case hubMenuOptionTapped = "hub_menu_option_tapped"
560+
case hubMenuSettingsTapped = "hub_menu_settings_tapped"
553561
}
554562

555563
public extension WooAnalyticsStat {

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ struct HubMenu: View {
3030

3131
LazyVGrid(columns: gridItemLayout, spacing: Constants.itemSpacing) {
3232
ForEach(viewModel.menuElements, id: \.self) { menu in
33-
HubMenuElement(image: menu.icon, text: menu.title)
34-
.frame(width: Constants.itemSize, height: Constants.itemSize)
35-
.contentShape(Rectangle())
36-
.onTapGesture {
37-
switch menu {
38-
case .woocommerceAdmin:
39-
showingWooCommerceAdmin = true
40-
case .viewStore:
41-
showingViewStore = true
42-
case .reviews:
43-
showingReviews = true
44-
case .coupons:
45-
showingCoupons = true
46-
}
33+
HubMenuElement(image: menu.icon, text: menu.title, onTapGesture: {
34+
switch menu {
35+
case .woocommerceAdmin:
36+
ServiceLocator.analytics.track(.hubMenuOptionTapped, withProperties: [Constants.option: "admin_menu"])
37+
showingWooCommerceAdmin = true
38+
case .viewStore:
39+
ServiceLocator.analytics.track(.hubMenuOptionTapped, withProperties: [Constants.option: "view_store"])
40+
showingViewStore = true
41+
case .reviews:
42+
ServiceLocator.analytics.track(.hubMenuOptionTapped, withProperties: [Constants.option: "reviews"])
43+
showingReviews = true
44+
case .coupons:
45+
ServiceLocator.analytics.track(.hubMenuOptionTapped, withProperties: [Constants.option: "coupons"])
46+
showingCoupons = true
4747
}
48+
})
4849
}
4950
.background(Color(.listForeground))
5051
.cornerRadius(Constants.cornerRadius)
@@ -129,6 +130,7 @@ struct HubMenu: View {
129130
}
130131
}
131132
.onTapGesture {
133+
ServiceLocator.analytics.track(.hubMenuSettingsTapped)
132134
showSettings = true
133135
}
134136
Spacer()
@@ -152,6 +154,7 @@ struct HubMenu: View {
152154
static let padding: CGFloat = 16
153155
static let topBarSpacing: CGFloat = 2
154156
static let avatarSize: CGFloat = 40
157+
static let option = "option"
155158
}
156159

157160
private enum Localization {

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuElement.swift

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,44 @@ import SwiftUI
55
struct HubMenuElement: View {
66
let image: UIImage
77
let text: String
8+
let onTapGesture: (() -> Void)
89

910
@ScaledMetric var imageSize: CGFloat = 58
1011
@ScaledMetric var iconSize: CGFloat = 34
1112

1213
var body: some View {
13-
VStack {
14-
ZStack {
15-
Color(UIColor(light: .listBackground,
16-
dark: .secondaryButtonBackground))
17-
Image(uiImage: image)
18-
.resizable()
19-
.scaledToFit()
20-
.frame(width: iconSize, height: iconSize)
14+
Button {
15+
onTapGesture()
16+
} label: {
17+
VStack {
18+
ZStack {
19+
Color(UIColor(light: .listBackground,
20+
dark: .secondaryButtonBackground))
21+
Image(uiImage: image)
22+
.resizable()
23+
.scaledToFit()
24+
.frame(width: iconSize, height: iconSize)
25+
}
26+
.frame(width: imageSize, height: imageSize, alignment: .center)
27+
.cornerRadius(imageSize/2)
28+
.padding(.bottom, Constants.paddingBetweenElements)
29+
Text(text)
30+
.bodyStyle()
2131
}
22-
.frame(width: imageSize, height: imageSize, alignment: .center)
23-
.cornerRadius(imageSize/2)
24-
.padding(.bottom, Constants.paddingBetweenElements)
25-
Text(text)
26-
.bodyStyle()
32+
.frame(width: Constants.itemSize, height: Constants.itemSize)
2733
}
2834
}
2935

3036
enum Constants {
3137
static let paddingBetweenElements: CGFloat = 8
38+
static let itemSize: CGFloat = 160
3239
}
3340
}
3441

3542
struct HubMenuElement_Previews: PreviewProvider {
3643
static var previews: some View {
37-
3844
HubMenuElement(image: .starOutlineImage(),
39-
text: "Menu")
45+
text: "Menu", onTapGesture: { })
4046
.previewLayout(.fixed(width: 160, height: 160))
4147
.previewDisplayName("Hub Menu Element")
4248
}

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class HubMenuViewModel: ObservableObject {
6262
/// Present the `StorePickerViewController` using the `StorePickerCoordinator`, passing the navigation controller from the entry point.
6363
///
6464
func presentSwitchStore() {
65-
//TODO-5509: add analytics events
65+
ServiceLocator.analytics.track(.hubMenuSwitchStoreTapped)
6666
if let navigationController = navigationController {
6767
storePickerCoordinator = StorePickerCoordinator(navigationController, config: .switchingStores)
6868
storePickerCoordinator?.start()

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private extension MainTabBarController {
226226
case .reviews:
227227
ServiceLocator.analytics.track(.notificationsSelected)
228228
case .hubMenu:
229-
//TODO-5509: implement tracking
229+
ServiceLocator.analytics.track(.hubMenuTabSelected)
230230
break
231231
}
232232
}
@@ -244,7 +244,7 @@ private extension MainTabBarController {
244244
case .reviews:
245245
ServiceLocator.analytics.track(.notificationsReselected)
246246
case .hubMenu:
247-
//TODO-5509: implement tracking
247+
ServiceLocator.analytics.track(.hubMenuTabReselected)
248248
break
249249
}
250250
}

0 commit comments

Comments
 (0)