Skip to content

Commit d2f21a5

Browse files
committed
Added tab changed tracks events in dashboard
1 parent c06c59b commit d2f21a5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public enum WooAnalyticsStat: String {
6363
case dashboardReselected = "main_tab_dashboard_reselected"
6464
case dashboardPulledToRefresh = "dashboard_pulled_to_refresh"
6565
case dashboardNewOrdersButtonTapped = "dashboard_unfulfilled_orders_button_tapped"
66+
case dashboardRevenueChartTabTapped = "dashboard_revenue_chart_tab_tapped"
67+
case dashboardTopPerformerTabTapped = "dashboard_top_performer_tab_tapped"
6668

6769
// Settings View Events
6870
//

WooCommerce/Classes/ViewRelated/Dashboard/MyStore/PeriodDataViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PeriodDataViewController: UIViewController, IndicatorInfoProvider {
2525
private var lastUpdatedDate: Date?
2626
private var yAxisMinimum: String = Constants.chartYAxisMinimum.friendlyString()
2727
private var yAxisMaximum: String = ""
28+
private var isInitialLoad: Bool = true // Used in trackChangedTabIfNeeded()
2829

2930
public let granularity: StatGranularity
3031
public var orderStats: OrderStats? {
@@ -109,6 +110,7 @@ class PeriodDataViewController: UIViewController, IndicatorInfoProvider {
109110
override func viewDidAppear(_ animated: Bool) {
110111
super.viewDidAppear(animated)
111112
reloadAllFields()
113+
trackChangedTabIfNeeded()
112114
}
113115

114116
override func viewDidDisappear(_ animated: Bool) {
@@ -309,6 +311,16 @@ private extension PeriodDataViewController {
309311
//
310312
private extension PeriodDataViewController {
311313

314+
func trackChangedTabIfNeeded() {
315+
// This is a little bit of a workaround to prevent the "tab tapped" tracks event from firing when launching the app.
316+
if granularity == .day && isInitialLoad {
317+
isInitialLoad = false
318+
return
319+
}
320+
WooAnalytics.shared.track(.dashboardRevenueChartTabTapped, withProperties: ["selected_tab": granularity.rawValue])
321+
isInitialLoad = false
322+
}
323+
312324
func reloadAllFields() {
313325
reloadOrderFields()
314326
reloadSiteFields()

WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformerDataViewController.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TopPerformerDataViewController: UIViewController, IndicatorInfoProvider {
2424
return ResultsController<StorageTopEarnerStats>(storageManager: storageManager, matching: predicate, sortedBy: [descriptor])
2525
}()
2626

27+
private var isInitialLoad: Bool = true // Used in trackChangedTabIfNeeded()
28+
2729
// MARK: - Computed Properties
2830

2931
private var topEarnerStats: TopEarnerStats? {
@@ -72,6 +74,11 @@ class TopPerformerDataViewController: UIViewController, IndicatorInfoProvider {
7274
registerTableViewCells()
7375
registerTableViewHeaderFooters()
7476
}
77+
78+
override func viewDidAppear(_ animated: Bool) {
79+
super.viewDidAppear(animated)
80+
trackChangedTabIfNeeded()
81+
}
7582
}
7683

7784

@@ -208,6 +215,16 @@ extension TopPerformerDataViewController: UITableViewDelegate {
208215
//
209216
private extension TopPerformerDataViewController {
210217

218+
func trackChangedTabIfNeeded() {
219+
// This is a little bit of a workaround to prevent the "tab tapped" tracks event from firing when launching the app.
220+
if granularity == .day && isInitialLoad {
221+
isInitialLoad = false
222+
return
223+
}
224+
WooAnalytics.shared.track(.dashboardTopPerformerTabTapped, withProperties: ["selected_tab": granularity.rawValue])
225+
isInitialLoad = false
226+
}
227+
211228
func statsItem(at indexPath: IndexPath) -> TopEarnerStatsItem? {
212229
guard let topEarnerStatsItem = topEarnerStats?.items?.sorted(by: >)[safe: indexPath.row] else {
213230
return nil

0 commit comments

Comments
 (0)