Context-aware routing to the Anytype iOS analytics system. Use when adding analytics events, tracking user routes, or working with AnytypeAnalytics and AnalyticsConstants.
Context-aware routing to the Anytype iOS analytics system. Helps you add analytics events, track user routes, and maintain consistent analytics patterns.
AnalyticsConstants.swift or AnytypeAnalytics+Events.swiftAnalyticsEventsPropertiesKey.*.rawValue.compactMapValues { $0 } for optional properties - Removes nil valuesAnalyticsConstants.swiftAnytypeAnalytics+Events.swiftAnytypeAnalytics.instance().logYourEvent(...)YourFeatureRoute to AnalyticsConstants.swiftroute: YourFeatureRoute? parameter// ViewModel
final class HomeWidgetsViewModel {
let route: HomeWidgetRoute?
func onAppear() {
AnytypeAnalytics.instance().logScreenWidget(route: route)
}
}
// Analytics method (AnytypeAnalytics+Events.swift)
func logScreenWidget(route: HomeWidgetRoute?) {
logEvent("ScreenWidget", withEventProperties: [
AnalyticsEventsPropertiesKey.route: route?.rawValue
].compactMapValues { $0 })
}
// Route enum (AnalyticsConstants.swift)
enum HomeWidgetRoute: String, Hashable, Codable {
case home = "Home"
case space = "Space"
case appLaunch = "AppLaunch"
}
// ViewModel
func onTapShare() {
AnytypeAnalytics.instance().logClickShare(type: .link, route: .settings)
output?.onShareSelected()
}
// Analytics method
func logClickShare(type: ShareType, route: ShareRoute) {
logEvent("ClickShare", withEventProperties: [
AnalyticsEventsPropertiesKey.type: type.rawValue,
AnalyticsEventsPropertiesKey.route: route.rawValue
])
}
func logCreateObject(objectType: AnalyticsObjectType, spaceId: String, route: AnalyticsEventsRouteKind) {
logEvent("CreateObject", spaceId: spaceId, withEventProperties: [
AnalyticsEventsPropertiesKey.objectType: objectType.analyticsId,
AnalyticsEventsPropertiesKey.route: route.rawValue
])
}
Always add to AnalyticsConstants.swift, grouped by feature:
// Widget-related routes
enum AnalyticsWidgetRoute: String {
case addWidget = "AddWidget"
case inner = "Inner"
}
enum HomeWidgetRoute: String, Hashable, Codable {
case home = "Home"
case space = "Space"
case appLaunch = "AppLaunch"
}
// Screen navigation routes
enum SettingsSpaceShareRoute: String {
case settings = "Settings"
case navigation = "Navigation"
case chat = "Chat"
}
Example: Adding route tracking to ScreenWidget
enum HomeWidgetRoute: String, Hashable, Codable {
case home = "Home" // Home button click
case space = "Space" // Space selection
case appLaunch = "AppLaunch" // App launch
}
struct HomeWidgetData: Hashable {
let spaceId: String
let route: HomeWidgetRoute? // Add route parameter
}
// Coordinator
HomeWidgetsView(info: info, output: model, route: data.route)
// View
HomeWidgetsViewModel(info: info, output: output, route: route)
// ViewModel
func onAppear() {
AnytypeAnalytics.instance().logScreenWidget(route: route)
}
// Analytics method
func logScreenWidget(route: HomeWidgetRoute?) {
logEvent("ScreenWidget", withEventProperties: [
AnalyticsEventsPropertiesKey.route: route?.rawValue
].compactMapValues { $0 })
}
// Home button
let data = HomeWidgetData(spaceId: spaceId, route: .home)
// Space selection
let data = HomeWidgetData(spaceId: spaceId, route: .space)
// App launch
let data = HomeWidgetData(spaceId: spaceId, route: .appLaunch)
Located in AnalyticsEventsPropertiesKey:
| Key | Usage | Example |
|---|---|---|
route |
Navigation context | .home, .navigation, .widget |
type |
Primary classification | .image, .video, .file |
objectType |
Object type ID | type.analyticsType.analyticsId |
spaceId |
Space identifier | document.spaceId |
count |
Quantity values | Number of items |
format |
Data format | File format, date format |
// WRONG
AnytypeAnalytics.instance().logScreenWidget(route: "Home")
// CORRECT
AnytypeAnalytics.instance().logScreenWidget(route: .home)
// WRONG - defined in feature file
enum HomeWidgetRoute: String {
case home = "Home"
}
// CORRECT - defined in AnalyticsConstants.swift
// WRONG - will include nil values as NSNull
[AnalyticsEventsPropertiesKey.route: route?.rawValue]
// CORRECT - removes nil values
[AnalyticsEventsPropertiesKey.route: route?.rawValue].compactMapValues { $0 }
// WRONG
["route": route.rawValue]
// CORRECT
[AnalyticsEventsPropertiesKey.route: route.rawValue]
# Search for existing events
rg "logEvent.*EventName" Anytype/Sources/Analytics/
# Find route enums
rg "enum.*Route.*String" Anytype/Sources/Analytics/AnalyticsConstants.swift
# Find property usage
rg "AnalyticsEventsPropertiesKey\." Anytype/Sources/Analytics/
# Find screen analytics
rg "func logScreen" Anytype/Sources/Analytics/AnytypeAnalytics+Events.swift
Full Guide: Anytype/Sources/PresentationLayer/Common/Analytics/ANALYTICS_PATTERNS.md
For comprehensive coverage of:
When adding analytics:
AnalyticsConstants.swiftAnytypeAnalytics+Events.swiftAnalyticsEventsPropertiesKey.*).compactMapValues { $0 }IOS_DEVELOPMENT_GUIDE.md - MVVM/Coordinator patterns for passing analytics dataNavigation: This is a smart router. For deep patterns and examples, always refer to ANALYTICS_PATTERNS.md.