@@ -126,7 +126,10 @@ private extension AnalyticsHubViewModel {
126126 try await self . retrieveOrderStats ( currentTimeRange: currentTimeRange, previousTimeRange: previousTimeRange)
127127 }
128128 group. addTask {
129- try await self . retrieveVisitorStats ( currentTimeRange: currentTimeRange, previousTimeRange: previousTimeRange)
129+ try await self . retrieveItemsSoldStats ( currentTimeRange: currentTimeRange, previousTimeRange: previousTimeRange)
130+ }
131+ group. addTask {
132+ try await self . retrieveSiteStats ( currentTimeRange: currentTimeRange)
130133 }
131134 try await group. waitForAll ( )
132135 }
@@ -147,7 +150,7 @@ private extension AnalyticsHubViewModel {
147150 }
148151
149152 @MainActor
150- func retrieveVisitorStats ( currentTimeRange: AnalyticsHubTimeRange , previousTimeRange: AnalyticsHubTimeRange ) async throws {
153+ func retrieveItemsSoldStats ( currentTimeRange: AnalyticsHubTimeRange , previousTimeRange: AnalyticsHubTimeRange ) async throws {
151154 async let itemsSoldRequest = retrieveTopItemsSoldStats ( earliestDateToInclude: currentTimeRange. start,
152155 latestDateToInclude: currentTimeRange. end,
153156 forceRefresh: true )
@@ -156,6 +159,14 @@ private extension AnalyticsHubViewModel {
156159 self . itemsSoldStats = itemsSoldStats
157160 }
158161
162+ @MainActor
163+ func retrieveSiteStats( currentTimeRange: AnalyticsHubTimeRange ) async throws {
164+ async let siteStatsRequest = retrieveSiteSummaryStats ( latestDateToInclude: currentTimeRange. end)
165+
166+ let summaryStats = try await siteStatsRequest
167+ self . siteStats = summaryStats
168+ }
169+
159170 @MainActor
160171 func retrieveStats( earliestDateToInclude: Date ,
161172 latestDateToInclude: Date ,
@@ -191,6 +202,25 @@ private extension AnalyticsHubViewModel {
191202 stores. dispatch ( action)
192203 }
193204 }
205+
206+ @MainActor
207+ /// Retrieves site summary stats using the `retrieveSiteSummaryStats` action.
208+ ///
209+ func retrieveSiteSummaryStats( latestDateToInclude: Date ) async throws -> SiteSummaryStats ? {
210+ guard let period = timeRangeSelectionType. period else {
211+ return nil
212+ }
213+
214+ return try await withCheckedThrowingContinuation { continuation in
215+ let action = StatsActionV4 . retrieveSiteSummaryStats ( siteID: siteID,
216+ period: period,
217+ quantity: timeRangeSelectionType. quantity,
218+ latestDateToInclude: latestDateToInclude) { result in
219+ continuation. resume ( with: result)
220+ }
221+ stores. dispatch ( action)
222+ }
223+ }
194224}
195225
196226// MARK: Data - UI mapping
@@ -202,13 +232,15 @@ private extension AnalyticsHubViewModel {
202232 self . ordersCard = ordersCard. redacted
203233 self . productsStatsCard = productsStatsCard. redacted
204234 self . itemsSoldCard = itemsSoldCard. redacted
235+ self . sessionsCard = sessionsCard. redacted
205236 }
206237
207238 @MainActor
208239 func switchToErrorState( ) {
209240 self . currentOrderStats = nil
210241 self . previousOrderStats = nil
211242 self . itemsSoldStats = nil
243+ self . siteStats = nil
212244 }
213245
214246 func bindViewModelsWithData( ) {
0 commit comments