Skip to content

Commit 02f357f

Browse files
committed
Add analytics to topic screen
1 parent 843a8cf commit 02f357f

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

ForPDA.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@
594594
B867C0932D8C528D00F1D060 /* ForumsListEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C0922D8C528D00F1D060 /* ForumsListEvent.swift */; };
595595
B867C0972D8C53B500F1D060 /* ForumFeature+Analytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C0962D8C53B500F1D060 /* ForumFeature+Analytics.swift */; };
596596
B867C09B2D8C543D00F1D060 /* ForumEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C09A2D8C543D00F1D060 /* ForumEvent.swift */; };
597+
B867C0A12D8C58A100F1D060 /* TopicFeature+Analytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C09F2D8C58A100F1D060 /* TopicFeature+Analytics.swift */; };
598+
B867C0A32D8C58AD00F1D060 /* TopicEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C0A22D8C58AD00F1D060 /* TopicEvent.swift */; };
597599
B8C498CEC48C5FCB4B97B06D /* LoggerClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE5B4E69183CAF50E2DD9C72 /* LoggerClient.framework */; };
598600
B8E07DB61EE1FE92476B3009 /* ArticleElementParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9364E09A93E9A621F26CEF92 /* ArticleElementParser.swift */; };
599601
B94FEA79A90DAADEAF9BA3BF /* FavoriteParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF90BDDA3C9FFDCACFC7076 /* FavoriteParser.swift */; };
@@ -2810,6 +2812,8 @@
28102812
B867C0922D8C528D00F1D060 /* ForumsListEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForumsListEvent.swift; sourceTree = "<group>"; };
28112813
B867C0962D8C53B500F1D060 /* ForumFeature+Analytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ForumFeature+Analytics.swift"; sourceTree = "<group>"; };
28122814
B867C09A2D8C543D00F1D060 /* ForumEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForumEvent.swift; sourceTree = "<group>"; };
2815+
B867C09F2D8C58A100F1D060 /* TopicFeature+Analytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TopicFeature+Analytics.swift"; sourceTree = "<group>"; };
2816+
B867C0A22D8C58AD00F1D060 /* TopicEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopicEvent.swift; sourceTree = "<group>"; };
28132817
BA6BE98BF8DC0AE85F30CC8B /* ZNSTextAttachment.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZNSTextAttachment.framework; sourceTree = BUILT_PRODUCTS_DIR; };
28142818
BA750927EA08B8979A02EE54 /* Links.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Links.swift; sourceTree = "<group>"; };
28152819
BABB677D51B18FF16F4CAEC2 /* TuistBundle+ForumsListFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TuistBundle+ForumsListFeature.swift"; sourceTree = "<group>"; };
@@ -4029,6 +4033,7 @@
40294033
B867C0922D8C528D00F1D060 /* ForumsListEvent.swift */,
40304034
B867C08C2D8C46D500F1D060 /* FavoritesEvent.swift */,
40314035
B867C09A2D8C543D00F1D060 /* ForumEvent.swift */,
4036+
B867C0A22D8C58AD00F1D060 /* TopicEvent.swift */,
40324037
);
40334038
path = Events;
40344039
sourceTree = "<group>";
@@ -4589,6 +4594,7 @@
45894594
ACEBF70460960A3EA57D36B3 /* TopicFeature */ = {
45904595
isa = PBXGroup;
45914596
children = (
4597+
B867C0A02D8C58A100F1D060 /* Analytics */,
45924598
1EE3AC7C8FB1DA367F8A1BC0 /* Models */,
45934599
A07239C2DF0E43964016CA5B /* Resources */,
45944600
B487A0FA81FA470EE3027064 /* TopicFeature.swift */,
@@ -4676,6 +4682,14 @@
46764682
path = Analytics;
46774683
sourceTree = "<group>";
46784684
};
4685+
B867C0A02D8C58A100F1D060 /* Analytics */ = {
4686+
isa = PBXGroup;
4687+
children = (
4688+
B867C09F2D8C58A100F1D060 /* TopicFeature+Analytics.swift */,
4689+
);
4690+
path = Analytics;
4691+
sourceTree = "<group>";
4692+
};
46794693
B982053D2330F26673C85EF0 /* Resources */ = {
46804694
isa = PBXGroup;
46814695
children = (
@@ -6583,6 +6597,7 @@
65836597
isa = PBXSourcesBuildPhase;
65846598
buildActionMask = 2147483647;
65856599
files = (
6600+
B867C0A32D8C58AD00F1D060 /* TopicEvent.swift in Sources */,
65866601
44A2962EEF02AF26E1E35CE8 /* TuistAssets+AnalyticsClient.swift in Sources */,
65876602
EFBEBBD55EC859DD137F08AD /* TuistBundle+AnalyticsClient.swift in Sources */,
65886603
B3018A8E7A3C5788FD3862B1 /* TuistFonts+AnalyticsClient.swift in Sources */,
@@ -6632,6 +6647,7 @@
66326647
buildActionMask = 2147483647;
66336648
files = (
66346649
314F5B6CFBCF136CAB69AC12 /* TuistAssets+TopicFeature.swift in Sources */,
6650+
B867C0A12D8C58A100F1D060 /* TopicFeature+Analytics.swift in Sources */,
66356651
4DB8144F0AEF7FC6E47B2C1B /* TuistBundle+TopicFeature.swift in Sources */,
66366652
FA66FD0AFA0FF01E8255B4F4 /* TuistFonts+TopicFeature.swift in Sources */,
66376653
97CE99F195BDCE44BE8BCBB2 /* TopicContextMenuAction.swift in Sources */,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// TopicEvent.swift
3+
// AnalyticsClient
4+
//
5+
// Created by Ilia Lubianoi on 20.03.2025.
6+
//
7+
8+
import Foundation
9+
10+
public enum TopicEvent: Event {
11+
// case onRefresh
12+
case userAvatarTapped(Int)
13+
case urlTapped(URL)
14+
15+
case menuCopyLink
16+
case menuOpenInBrowser
17+
case menuGoToEnd
18+
case menuSetFavorite
19+
20+
case loadingStart(Int)
21+
case loadingSuccess
22+
case loadingFailure(any Error)
23+
case setFavoriteResponse(Bool)
24+
25+
public var name: String {
26+
return "Topic " + eventName(for: self).inProperCase
27+
}
28+
29+
public var properties: [String: String]? {
30+
switch self {
31+
case let .userAvatarTapped(id):
32+
return ["userId": String(id)]
33+
34+
case let .urlTapped(url):
35+
return ["url": url.absoluteString]
36+
37+
case let .loadingStart(offset):
38+
return ["offset": String(offset)]
39+
40+
case let .loadingFailure(error):
41+
return ["error": error.localizedDescription]
42+
43+
case let .setFavoriteResponse(state):
44+
return ["state": state.description]
45+
46+
default:
47+
return nil
48+
}
49+
}
50+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// TopicFeature+Analytics.swift
3+
// ForPDA
4+
//
5+
// Created by Ilia Lubianoi on 20.03.2025.
6+
//
7+
8+
import ComposableArchitecture
9+
import AnalyticsClient
10+
11+
extension TopicFeature {
12+
13+
struct Analytics: Reducer {
14+
typealias State = TopicFeature.State
15+
typealias Action = TopicFeature.Action
16+
17+
@Dependency(\.analyticsClient) var analytics
18+
19+
var body: some Reducer<State, Action> {
20+
Reduce<State, Action> { state, action in
21+
switch action {
22+
case .onTask, .pageNavigation, ._loadTypes:
23+
break
24+
25+
case let .userAvatarTapped(userId: userId):
26+
analytics.log(TopicEvent.userAvatarTapped(userId))
27+
28+
case let .urlTapped(url):
29+
analytics.log(TopicEvent.urlTapped(url))
30+
31+
case let .contextMenu(option):
32+
switch option {
33+
case .copyLink:
34+
analytics.log(TopicEvent.menuCopyLink)
35+
case .openInBrowser:
36+
analytics.log(TopicEvent.menuOpenInBrowser)
37+
case .goToEnd:
38+
analytics.log(TopicEvent.menuGoToEnd)
39+
case .setFavorite:
40+
analytics.log(TopicEvent.menuSetFavorite)
41+
}
42+
43+
case let ._loadTopic(offset: offset):
44+
analytics.log(TopicEvent.loadingStart(offset))
45+
46+
case let ._topicResponse(response):
47+
switch response {
48+
case .success:
49+
analytics.log(TopicEvent.loadingSuccess)
50+
case let .failure(error):
51+
analytics.log(TopicEvent.loadingFailure(error))
52+
}
53+
54+
case let ._setFavoriteResponse(response):
55+
analytics.log(TopicEvent.setFavoriteResponse(response))
56+
}
57+
58+
return .none
59+
}
60+
}
61+
}
62+
}

Modules/Sources/TopicFeature/TopicFeature.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public struct TopicFeature: Reducer, Sendable {
223223
return .none
224224
}
225225
}
226+
227+
Analytics()
226228
}
227229

228230
// MARK: - Shared Logic

0 commit comments

Comments
 (0)