@@ -13,6 +13,7 @@ import APIClient
1313import CacheClient
1414import PasteboardClient
1515import HapticClient
16+ import AnalyticsClient
1617
1718@Reducer
1819public struct ArticleFeature : Reducer , Sendable {
@@ -64,6 +65,8 @@ public struct ArticleFeature: Reducer, Sendable {
6465 var refreshRequestFinished = false
6566 var refreshTimePassed = false
6667
68+ var didLoadOnce = false
69+
6770 public init (
6871 destination: Destination . State ? = nil ,
6972 articlePreview: ArticlePreview ,
@@ -133,6 +136,7 @@ public struct ArticleFeature: Reducer, Sendable {
133136 @Dependency ( \. cacheClient) var cacheClient
134137 @Dependency ( \. hapticClient) var hapticClient
135138 @Dependency ( \. parsingClient) var parsingClient
139+ @Dependency ( \. analyticsClient) var analyticsClient
136140 @Dependency ( \. pasteboardClient) var pasteboardClient
137141 @Dependency ( \. openURL) var openURL
138142 @Dependency ( \. dismiss) var dismiss
@@ -323,6 +327,7 @@ public struct ArticleFeature: Reducer, Sendable {
323327 case . _articleResponse( . failure) :
324328 state. isLoading = false
325329 state. destination = . alert( . error)
330+ reportFullyDisplayed ( & state)
326331 return . none
327332
328333 case let . _commentResponse( . success( type) ) :
@@ -355,6 +360,7 @@ public struct ArticleFeature: Reducer, Sendable {
355360 case . _parseArticleElements( . success( let elements) ) :
356361 state. elements = elements
357362 state. isLoading = false
363+ reportFullyDisplayed ( & state)
358364 return . run { _ in
359365 var urls : [ URL ] = [ ]
360366 for case let . image( image) in elements {
@@ -366,6 +372,7 @@ public struct ArticleFeature: Reducer, Sendable {
366372 case . _parseArticleElements( . failure) :
367373 state. isLoading = false
368374 state. destination = . alert( . error)
375+ reportFullyDisplayed ( & state)
369376 return . none
370377
371378 case . _pollVoteResponse( . success) :
@@ -389,7 +396,13 @@ public struct ArticleFeature: Reducer, Sendable {
389396 Analytics ( )
390397 }
391398
392- // MARK: - Effects
399+ // MARK: - Shared Logic
400+
401+ private func reportFullyDisplayed( _ state: inout State ) {
402+ guard !state. didLoadOnce else { return }
403+ analyticsClient. reportFullyDisplayed ( )
404+ state. didLoadOnce = true
405+ }
393406
394407 private func loadingIndicator( ) -> EffectOf < Self > {
395408 return . run { send in
0 commit comments