Skip to content

Commit 47fc338

Browse files
authored
Merge pull request #4221 from anyproto/ios-5428-analytics-research
IOS-5428 Log widgets appearance
2 parents e0bfa2a + b7ed3c7 commit 47fc338

File tree

7 files changed

+38
-23
lines changed

7 files changed

+38
-23
lines changed

Anytype/Sources/Analytics/AnalyticsConstants.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ enum AnalyticsWidgetContext: String, Hashable {
171171
case auto = "Auto"
172172
}
173173

174+
enum HomeWidgetRoute: String, Hashable, Codable {
175+
case home = "Home"
176+
case space = "Space"
177+
case appLaunch = "AppLaunch"
178+
}
179+
174180
enum RemoveCompletelyRoute: String {
175181
case bin = "Bin"
176182
case settings = "Settings"

Anytype/Sources/Analytics/AnytypeAnalytics/AnytypeAnalytics+Events.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,10 @@ extension AnytypeAnalytics {
13191319
logEvent("HistoryBack")
13201320
}
13211321

1322-
func logScreenWidget() {
1323-
logEvent("ScreenWidget")
1322+
func logScreenWidget(route: HomeWidgetRoute?) {
1323+
logEvent("ScreenWidget", withEventProperties: [
1324+
AnalyticsEventsPropertiesKey.route: route?.rawValue
1325+
].compactMapValues { $0 })
13241326
}
13251327

13261328
func logScreenBin() {

Anytype/Sources/PresentationLayer/Flows/HomeWidgetsCoordinator/HomeWidgetsCoordinatorView.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@ import Services
44

55
struct HomeWidgetData: Hashable {
66
let spaceId: String
7+
let route: HomeWidgetRoute?
78
}
89

910
struct HomeWidgetsCoordinatorView: View {
1011
let data: HomeWidgetData
11-
12+
1213
var body: some View {
1314
SpaceLoadingContainerView(spaceId: data.spaceId, showBackground: true) {
14-
HomeWidgetsCoordinatorInternalView(info: $0)
15+
HomeWidgetsCoordinatorInternalView(info: $0, route: data.route)
1516
}
1617
}
1718
}
1819

1920
private struct HomeWidgetsCoordinatorInternalView: View {
20-
21+
2122
@State private var model: HomeWidgetsCoordinatorViewModel
2223
@Environment(\.pageNavigation) private var pageNavigation
23-
24-
init(info: AccountInfo) {
24+
let route: HomeWidgetRoute?
25+
26+
init(info: AccountInfo, route: HomeWidgetRoute?) {
2527
self._model = State(wrappedValue: HomeWidgetsCoordinatorViewModel(info: info))
28+
self.route = route
2629
}
2730

2831
var body: some View {
29-
HomeWidgetsView(info: model.spaceInfo, output: model)
32+
HomeWidgetsView(info: model.spaceInfo, output: model, route: route)
3033
.onAppear {
3134
model.pageNavigation = pageNavigation
3235
}

Anytype/Sources/PresentationLayer/Flows/SpaceHub/SpaceHubCoordinatorViewModel.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ final class SpaceHubCoordinatorViewModel: SpaceHubModuleOutput {
6161
self?.showScreenSync(data: data)
6262
}, pushHome: { [weak self] in
6363
guard let self, let currentSpaceId else { return }
64-
navigationPath.push(HomeWidgetData(spaceId: currentSpaceId))
64+
navigationPath.push(HomeWidgetData(spaceId: currentSpaceId, route: .home))
6565
}, pop: { [weak self] in
6666
self?.navigationPath.pop()
6767
}, popToFirstInSpace: { [weak self] in
@@ -163,12 +163,12 @@ final class SpaceHubCoordinatorViewModel: SpaceHubModuleOutput {
163163

164164
func setupInitialScreen() async {
165165
guard !loginStateService.isFirstLaunchAfterRegistration, appActionsStorage.action.isNil else { return }
166-
166+
167167
switch userDefaults.lastOpenedScreen {
168168
case .editor(let editorData):
169169
try? await showScreen(data: .editor(editorData))
170170
case .widgets(let spaceId):
171-
try? await showScreen(data: .widget(HomeWidgetData(spaceId: spaceId)))
171+
try? await showScreen(data: .widget(HomeWidgetData(spaceId: spaceId, route: .appLaunch)))
172172
case .chat(let data):
173173
try? await showScreen(data: .chat(data))
174174
case .spaceChat(let data):
@@ -308,7 +308,7 @@ final class SpaceHubCoordinatorViewModel: SpaceHubModuleOutput {
308308
let chatData = SpaceChatCoordinatorData(spaceId: spaceView.targetSpaceId)
309309
try await showScreen(data: .spaceChat(chatData))
310310
} else {
311-
let widgetData = HomeWidgetData(spaceId: spaceView.targetSpaceId)
311+
let widgetData = HomeWidgetData(spaceId: spaceView.targetSpaceId, route: .space)
312312
try await showScreen(data: .widget(widgetData))
313313
}
314314
}
@@ -357,7 +357,7 @@ final class SpaceHubCoordinatorViewModel: SpaceHubModuleOutput {
357357
case .spaceChat(let data):
358358
currentPath.openOnce(data)
359359
case .widget(let data):
360-
let data = HomeWidgetData(spaceId: data.spaceId)
360+
let data = HomeWidgetData(spaceId: data.spaceId, route: nil)
361361
currentPath.openOnce(data)
362362
}
363363

@@ -433,7 +433,7 @@ final class SpaceHubCoordinatorViewModel: SpaceHubModuleOutput {
433433
if spaceView.initialScreenIsChat {
434434
SpaceChatCoordinatorData(spaceId: spaceView.targetSpaceId)
435435
} else {
436-
HomeWidgetData(spaceId: spaceView.targetSpaceId)
436+
HomeWidgetData(spaceId: spaceView.targetSpaceId, route: nil)
437437
}
438438
}
439439
}

Anytype/Sources/PresentationLayer/Flows/SpaceHub/Support/SpaceHubPathManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class SpaceHubPathUXTypeHelper: SpaceHubPathUXTypeHelperProtocol {
2020
case .data:
2121
// Expected: SpaceHubNavigationItem, HomeWidgetData
2222
let chatItem = SpaceChatCoordinatorData(spaceId: spaceView.targetSpaceId)
23-
let homeItem = HomeWidgetData(spaceId: spaceView.targetSpaceId)
23+
let homeItem = HomeWidgetData(spaceId: spaceView.targetSpaceId, route: nil)
2424
path.remove(chatItem)
2525
path.remove(homeItem)
2626
path.insert(homeItem, at: 1)

Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsView.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import AnytypeCore
66
struct HomeWidgetsView: View {
77
let info: AccountInfo
88
let output: (any HomeWidgetsModuleOutput)?
9-
9+
let route: HomeWidgetRoute?
10+
1011
var body: some View {
11-
HomeWidgetsInternalView(info: info, output: output)
12+
HomeWidgetsInternalView(info: info, output: output, route: route)
1213
.id(info.hashValue)
1314
}
1415
}
@@ -17,9 +18,9 @@ private struct HomeWidgetsInternalView: View {
1718
@State private var model: HomeWidgetsViewModel
1819
@State var widgetsDndState = DragState()
1920
@State var typesDndState = DragState()
20-
21-
init(info: AccountInfo, output: (any HomeWidgetsModuleOutput)?) {
22-
self._model = State(wrappedValue: HomeWidgetsViewModel(info: info, output: output))
21+
22+
init(info: AccountInfo, output: (any HomeWidgetsModuleOutput)?, route: HomeWidgetRoute?) {
23+
self._model = State(wrappedValue: HomeWidgetsViewModel(info: info, output: output, route: route))
2324
}
2425

2526
var body: some View {

Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsViewModel.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ final class HomeWidgetsViewModel {
1414
}
1515

1616
// MARK: - DI
17-
17+
1818
let info: AccountInfo
1919
let widgetObject: any BaseDocumentProtocol
20+
let route: HomeWidgetRoute?
2021

2122
@Injected(\.blockWidgetService) @ObservationIgnored
2223
private var blockWidgetService: any BlockWidgetServiceProtocol
@@ -56,10 +57,12 @@ final class HomeWidgetsViewModel {
5657

5758
init(
5859
info: AccountInfo,
59-
output: (any HomeWidgetsModuleOutput)?
60+
output: (any HomeWidgetsModuleOutput)?,
61+
route: HomeWidgetRoute?
6062
) {
6163
self.info = info
6264
self.output = output
65+
self.route = route
6366
self.widgetObject = documentService.document(objectId: info.widgetsId, spaceId: info.accountSpaceId)
6467
self.pinnedSectionIsExpanded = expandedService.isExpanded(id: Constants.pinnedSectionId, defaultValue: true)
6568
self.objectTypeSectionIsExpanded = expandedService.isExpanded(id: Constants.objectTypeSectionId, defaultValue: true)
@@ -74,7 +77,7 @@ final class HomeWidgetsViewModel {
7477
}
7578

7679
func onAppear() {
77-
AnytypeAnalytics.instance().logScreenWidget()
80+
AnytypeAnalytics.instance().logScreenWidget(route: route)
7881
}
7982

8083
func widgetsDropUpdate(from: DropDataElement<BlockWidgetInfo>, to: DropDataElement<BlockWidgetInfo>) {

0 commit comments

Comments
 (0)