Skip to content

Commit 9afae0b

Browse files
joshhealdclaude
andcommitted
[Local catalog] Add analytics tracking for local search
- Rename analytics event from pointOfSaleSearchLocalResultsFetched to pointOfSaleSearchResultsFetched - Change stat name from search_local_results_fetched to search_results_fetched - Add analytics tracking to local search strategy fetchProducts method - Track milliseconds since request sent and total results count - Only track on first page to avoid duplicate analytics The new event name reflects that this will be the only search method in the future when local catalog is fully rolled out. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3e82715 commit 9afae0b

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

Modules/Sources/PointOfSale/Analytics/POSItemFetchAnalytics.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ struct POSItemFetchAnalytics: POSItemFetchAnalyticsTracking {
4646

4747
/// Tracks when a local search results fetch completes
4848
/// - Parameters:
49-
/// - milliseconds: The time taken to fetch results in milliseconds
49+
/// - millisecondsSinceRequestSent: The time taken to fetch results in milliseconds
5050
/// - totalItems: The total number of items found in the search
5151
func trackSearchLocalResultsFetchComplete(millisecondsSinceRequestSent: Int, totalItems: Int) {
52-
// TODO: Implement analytics event for local search results
53-
// This will be implemented in the final PR
52+
analytics.track(
53+
event: .PointOfSale.pointOfSaleSearchResultsFetched(
54+
itemType: itemType,
55+
resultsCount: totalItems,
56+
millisecondsSinceRequestSent: millisecondsSinceRequestSent
57+
)
58+
)
5459
}
5560
}

Modules/Sources/PointOfSale/Analytics/WooAnalyticsEvent+PointOfSale.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ extension WooAnalyticsEvent {
305305
])
306306
}
307307

308+
static func pointOfSaleSearchResultsFetched(itemType: POSItemType,
309+
resultsCount: Int,
310+
millisecondsSinceRequestSent: Int) -> WooAnalyticsEvent {
311+
WooAnalyticsEvent(statName: .pointOfSaleSearchResultsFetched,
312+
properties: [
313+
Key.sourceView: SourceView(itemType: itemType).rawValue,
314+
Key.resultsCount: "\(resultsCount)",
315+
Key.millisecondsSinceRequestSent: "\(millisecondsSinceRequestSent)"
316+
])
317+
}
318+
308319
static func pointOfSaleItemsFetched(itemType: POSItemType,
309320
totalItems: Int) -> WooAnalyticsEvent {
310321
WooAnalyticsEvent(statName: .pointOfSaleItemsFetched,

Modules/Sources/WooFoundationCore/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ public enum WooAnalyticsStat: String {
12751275
case pointOfSaleKeyboardDismissedInSearch = "keyboard_dismissed_in_search"
12761276
case pointOfSaleItemsNextPageLoaded = "items_next_page_loaded"
12771277
case pointOfSaleSearchRemoteResultsFetched = "search_remote_results_fetched"
1278+
case pointOfSaleSearchResultsFetched = "search_results_fetched"
12781279
case pointOfSaleBarcodeScanningMenuItemTapped = "barcode_scanning_menu_item_tapped"
12791280
case pointOfSaleBarcodeScanningExplanationDialogShown = "barcode_scanning_explanation_dialog_shown"
12801281
case pointOfSaleBarcodeScannerSetupFlowShown = "barcode_scanner_setup_flow_shown"

Modules/Sources/Yosemite/PointOfSale/Items/PointOfSaleLocalSearchPurchasableItemFetchStrategy.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public struct PointOfSaleLocalSearchPurchasableItemFetchStrategy: PointOfSalePur
2626
}
2727

2828
public func fetchProducts(pageNumber: Int) async throws -> PagedItems<POSProduct> {
29+
let startTime = Date()
30+
2931
// Get total count and persisted products in one transaction
3032
let (persistedProducts, totalCount) = try await grdbManager.databaseConnection.read { db in
3133
let totalCount = try PersistedProduct
@@ -49,6 +51,12 @@ public struct PointOfSaleLocalSearchPurchasableItemFetchStrategy: PointOfSalePur
4951

5052
let hasMorePages = (pageNumber * pageSize) < totalCount
5153

54+
if pageNumber == 1 {
55+
let milliseconds = Int(Date().timeIntervalSince(startTime) * Double(MSEC_PER_SEC))
56+
analytics.trackSearchLocalResultsFetchComplete(millisecondsSinceRequestSent: milliseconds,
57+
totalItems: totalCount)
58+
}
59+
5260
return PagedItems(items: products,
5361
hasMorePages: hasMorePages,
5462
totalItems: totalCount)

WooCommerce/Classes/Analytics/TracksProvider.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ private extension TracksProvider {
150150
WooAnalyticsStat.pointOfSaleKeyboardDismissedInSearch,
151151
WooAnalyticsStat.pointOfSaleItemsNextPageLoaded,
152152
WooAnalyticsStat.pointOfSaleSearchRemoteResultsFetched,
153+
WooAnalyticsStat.pointOfSaleSearchResultsFetched,
153154
WooAnalyticsStat.pointOfSaleBarcodeScanningMenuItemTapped,
154155
WooAnalyticsStat.pointOfSaleBarcodeScanningExplanationDialogShown,
155156
WooAnalyticsStat.pointOfSaleBarcodeScannerSetupFlowShown,

0 commit comments

Comments
 (0)