Skip to content

Commit 843a8cf

Browse files
committed
Add analytics to forum screen
1 parent 466a9be commit 843a8cf

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

ForPDA.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@
592592
B867C08D2D8C46D500F1D060 /* FavoritesEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C08C2D8C46D500F1D060 /* FavoritesEvent.swift */; };
593593
B867C0912D8C521200F1D060 /* ForumsListFeature+Analytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C0902D8C521200F1D060 /* ForumsListFeature+Analytics.swift */; };
594594
B867C0932D8C528D00F1D060 /* ForumsListEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C0922D8C528D00F1D060 /* ForumsListEvent.swift */; };
595+
B867C0972D8C53B500F1D060 /* ForumFeature+Analytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C0962D8C53B500F1D060 /* ForumFeature+Analytics.swift */; };
596+
B867C09B2D8C543D00F1D060 /* ForumEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B867C09A2D8C543D00F1D060 /* ForumEvent.swift */; };
595597
B8C498CEC48C5FCB4B97B06D /* LoggerClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE5B4E69183CAF50E2DD9C72 /* LoggerClient.framework */; };
596598
B8E07DB61EE1FE92476B3009 /* ArticleElementParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9364E09A93E9A621F26CEF92 /* ArticleElementParser.swift */; };
597599
B94FEA79A90DAADEAF9BA3BF /* FavoriteParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF90BDDA3C9FFDCACFC7076 /* FavoriteParser.swift */; };
@@ -2806,6 +2808,8 @@
28062808
B867C08C2D8C46D500F1D060 /* FavoritesEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesEvent.swift; sourceTree = "<group>"; };
28072809
B867C0902D8C521200F1D060 /* ForumsListFeature+Analytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ForumsListFeature+Analytics.swift"; sourceTree = "<group>"; };
28082810
B867C0922D8C528D00F1D060 /* ForumsListEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForumsListEvent.swift; sourceTree = "<group>"; };
2811+
B867C0962D8C53B500F1D060 /* ForumFeature+Analytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ForumFeature+Analytics.swift"; sourceTree = "<group>"; };
2812+
B867C09A2D8C543D00F1D060 /* ForumEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForumEvent.swift; sourceTree = "<group>"; };
28092813
BA6BE98BF8DC0AE85F30CC8B /* ZNSTextAttachment.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZNSTextAttachment.framework; sourceTree = BUILT_PRODUCTS_DIR; };
28102814
BA750927EA08B8979A02EE54 /* Links.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Links.swift; sourceTree = "<group>"; };
28112815
BABB677D51B18FF16F4CAEC2 /* TuistBundle+ForumsListFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TuistBundle+ForumsListFeature.swift"; sourceTree = "<group>"; };
@@ -4024,6 +4028,7 @@
40244028
B867C0812D8C0B0900F1D060 /* FavoritesRootEvent.swift */,
40254029
B867C0922D8C528D00F1D060 /* ForumsListEvent.swift */,
40264030
B867C08C2D8C46D500F1D060 /* FavoritesEvent.swift */,
4031+
B867C09A2D8C543D00F1D060 /* ForumEvent.swift */,
40274032
);
40284033
path = Events;
40294034
sourceTree = "<group>";
@@ -4106,6 +4111,7 @@
41064111
698CA54640E301F64BDE9396 /* ForumFeature */ = {
41074112
isa = PBXGroup;
41084113
children = (
4114+
B867C0952D8C53B500F1D060 /* Analytics */,
41094115
6BA0B264329742A6E165E105 /* Models */,
41104116
68CC0177BE43AD01FE3DB8FE /* Resources */,
41114117
DE1802B1757DD0294A45CBEB /* ForumFeature.swift */,
@@ -4662,6 +4668,14 @@
46624668
path = Analytics;
46634669
sourceTree = "<group>";
46644670
};
4671+
B867C0952D8C53B500F1D060 /* Analytics */ = {
4672+
isa = PBXGroup;
4673+
children = (
4674+
B867C0962D8C53B500F1D060 /* ForumFeature+Analytics.swift */,
4675+
);
4676+
path = Analytics;
4677+
sourceTree = "<group>";
4678+
};
46654679
B982053D2330F26673C85EF0 /* Resources */ = {
46664680
isa = PBXGroup;
46674681
children = (
@@ -6581,6 +6595,7 @@
65816595
1869C6EEB8CCB4F0A8356CE9 /* Event.swift in Sources */,
65826596
CA65F52046767C63F6B38B83 /* LoginEvent.swift in Sources */,
65836597
8781F75A021319CF6929018E /* MenuEvent.swift in Sources */,
6598+
B867C09B2D8C543D00F1D060 /* ForumEvent.swift in Sources */,
65846599
B7719EDD4CB97FBDC14187F0 /* ProfileEvent.swift in Sources */,
65856600
B867C08D2D8C46D500F1D060 /* FavoritesEvent.swift in Sources */,
65866601
1AC77153F4BED487DE8A5D59 /* SettingsEvent.swift in Sources */,
@@ -6746,6 +6761,7 @@
67466761
5F21D254E99407336A6ECF86 /* ForumCommonContextMenuAction.swift in Sources */,
67476762
F2AA56B620186D83C28A3E54 /* ForumOptionContextMenuAction.swift in Sources */,
67486763
5F9DEFC8B70EF38CCB3CAC30 /* ForumTopicContextMenuAction.swift in Sources */,
6764+
B867C0972D8C53B500F1D060 /* ForumFeature+Analytics.swift in Sources */,
67496765
);
67506766
runOnlyForDeploymentPostprocessing = 0;
67516767
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// ForumEvent.swift
3+
// AnalyticsClient
4+
//
5+
// Created by Ilia Lubianoi on 20.03.2025.
6+
//
7+
8+
import Foundation
9+
10+
public enum ForumEvent: Event {
11+
case onRefresh
12+
case settingsButtonTapped
13+
case topicTapped(Int, Int)
14+
case subforumRedirectTapped(URL)
15+
case subforumTapped(Int, String)
16+
case announcementTapped(Int, String)
17+
18+
// case menuSort
19+
// case menuBookmarks
20+
21+
case menuOpen(Int)
22+
case menuGoToEnd(Int)
23+
24+
case menuMarkRead(Int, Bool)
25+
case menuCopyLink(Int, Bool)
26+
case menuOpenInBrowser(Int, Bool)
27+
case menuSetFavorite(Int, Bool, Bool)
28+
29+
case loadingStart(Int)
30+
case loadingSuccess
31+
case loadingFailure(any Error)
32+
33+
public var name: String {
34+
return "Forum " + eventName(for: self).inProperCase
35+
}
36+
37+
public var properties: [String: String]? {
38+
switch self {
39+
case let .topicTapped(id, offset):
40+
return ["id": String(id), "offset": String(offset)]
41+
42+
case let .subforumRedirectTapped(url):
43+
return ["url": url.absoluteString]
44+
45+
case let .subforumTapped(id, name):
46+
return ["id": String(id), "name": name]
47+
48+
case let .announcementTapped(id, name):
49+
return ["id": String(id), "name": name]
50+
51+
case let .menuOpen(id):
52+
return ["id": String(id)]
53+
54+
case let .menuGoToEnd(id):
55+
return ["id": String(id)]
56+
57+
case let .menuMarkRead(id, isForum):
58+
return ["id": String(id), "isForum": String(isForum)]
59+
60+
case let .menuCopyLink(id, isForum):
61+
return ["id": String(id), "isForum": String(isForum)]
62+
63+
case let .menuOpenInBrowser(id, isForum):
64+
return ["id": String(id), "isForum": String(isForum)]
65+
66+
case let .menuSetFavorite(id, isForum, state):
67+
return ["id": String(id), "isForum": String(isForum), "state": state.description]
68+
69+
case let .loadingStart(offset):
70+
return ["offset": String(offset)]
71+
72+
case let .loadingFailure(error):
73+
return ["error": error.localizedDescription]
74+
75+
default:
76+
return nil
77+
}
78+
}
79+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// ForumFeature+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 ForumFeature {
12+
13+
struct Analytics: Reducer {
14+
typealias State = ForumFeature.State
15+
typealias Action = ForumFeature.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 .onAppear, .pageNavigation:
23+
break
24+
25+
case .onRefresh:
26+
analytics.log(ForumEvent.onRefresh)
27+
28+
case .settingsButtonTapped:
29+
analytics.log(ForumEvent.settingsButtonTapped)
30+
31+
case let .topicTapped(id: id, offset: offset):
32+
analytics.log(ForumEvent.topicTapped(id, offset))
33+
34+
case let .subforumRedirectTapped(url):
35+
analytics.log(ForumEvent.subforumRedirectTapped(url))
36+
37+
case let .subforumTapped(id: id, name: name):
38+
analytics.log(ForumEvent.subforumTapped(id, name))
39+
40+
case let .announcementTapped(id: id, name: name):
41+
analytics.log(ForumEvent.announcementTapped(id, name))
42+
43+
case let .contextOptionMenu(option):
44+
switch option {
45+
case .sort:
46+
break // TODO: Add
47+
case .toBookmarks:
48+
break // TODO: Add
49+
}
50+
case let .contextTopicMenu(option, id):
51+
switch option {
52+
case .open:
53+
analytics.log(ForumEvent.menuOpen(id))
54+
case .goToEnd:
55+
analytics.log(ForumEvent.menuGoToEnd(id))
56+
}
57+
case let .contextCommonMenu(option, id, isForum):
58+
switch option {
59+
case .markRead:
60+
analytics.log(ForumEvent.menuMarkRead(id, isForum))
61+
case .copyLink:
62+
analytics.log(ForumEvent.menuCopyLink(id, isForum))
63+
case .openInBrowser:
64+
analytics.log(ForumEvent.menuOpenInBrowser(id, isForum))
65+
case let .setFavorite(state):
66+
analytics.log(ForumEvent.menuSetFavorite(id, isForum, state))
67+
}
68+
69+
case let ._loadForum(offset: offset):
70+
analytics.log(ForumEvent.loadingStart(offset))
71+
72+
case let ._forumResponse(response):
73+
switch response {
74+
case .success:
75+
analytics.log(ForumEvent.loadingSuccess)
76+
case let .failure(error):
77+
analytics.log(ForumEvent.loadingFailure(error))
78+
}
79+
}
80+
81+
return .none
82+
}
83+
}
84+
}
85+
}

Modules/Sources/ForumFeature/ForumFeature.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public struct ForumFeature: Reducer, Sendable {
138138
case .contextOptionMenu(let action):
139139
switch action {
140140
// TODO: sort, to bookmarks
141+
// TODO: Add analytics
141142
default: return .none
142143
}
143144

@@ -221,6 +222,8 @@ public struct ForumFeature: Reducer, Sendable {
221222
return .none
222223
}
223224
}
225+
226+
Analytics()
224227
}
225228

226229
// MARK: - Shared Logic

0 commit comments

Comments
 (0)