Skip to content

Commit 949bebc

Browse files
authored
Merge pull request #4224 from anyproto/ios-5416-add-user-properties-for-all-amplitude-events
iOS-5416 Analytics | add user properties for all amplitude events
2 parents f9729e6 + a3abd5f commit 949bebc

File tree

25 files changed

+77
-89
lines changed

25 files changed

+77
-89
lines changed

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

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ extension AnytypeAnalytics {
156156
)
157157
}
158158

159-
func logChangeObjectType(_ type: AnalyticsObjectType, spaceId: String, route: ChangeObjectTypeRoute? = nil) {
159+
func logChangeObjectType(_ type: AnalyticsObjectType, route: ChangeObjectTypeRoute? = nil) {
160160
logEvent(
161161
"ChangeObjectType",
162-
spaceId: spaceId,
163162
withEventProperties: [
164163
AnalyticsEventsPropertiesKey.objectType: type.analyticsId,
165164
AnalyticsEventsPropertiesKey.route: route?.rawValue
@@ -241,21 +240,19 @@ extension AnytypeAnalytics {
241240
logEvent("DeleteBlock")
242241
}
243242

244-
func logUploadMedia(type: FileContentType, spaceId: String, route: UploadMediaRoute) {
243+
func logUploadMedia(type: FileContentType, route: UploadMediaRoute) {
245244
logEvent(
246245
"UploadMedia",
247-
spaceId: spaceId,
248246
withEventProperties: [
249247
AnalyticsEventsPropertiesKey.type: type.rawValue,
250248
AnalyticsEventsPropertiesKey.route: route.rawValue
251249
]
252250
)
253251
}
254252

255-
func logDownloadMedia(type: FileContentType, spaceId: String) {
253+
func logDownloadMedia(type: FileContentType) {
256254
logEvent(
257255
"DownloadMedia",
258-
spaceId: spaceId,
259256
withEventProperties: [AnalyticsEventsPropertiesKey.type: type.rawValue]
260257
)
261258
}
@@ -270,7 +267,6 @@ extension AnytypeAnalytics {
270267
isNew: Bool,
271268
type: AnalyticsEventsRelationType,
272269
key: AnalyticsRelationKey,
273-
spaceId: String,
274270
route: AnalyticsEventsRouteKind? = nil
275271
) {
276272
let properties = [
@@ -282,7 +278,6 @@ extension AnytypeAnalytics {
282278

283279
logEvent(
284280
isNew ? "CreateRelation" : "AddExistingRelation",
285-
spaceId: spaceId,
286281
withEventProperties: properties
287282
)
288283
}
@@ -291,12 +286,10 @@ extension AnytypeAnalytics {
291286
isEmpty: Bool,
292287
format: PropertyFormat,
293288
type: AnalyticsEventsRelationType,
294-
key: AnalyticsRelationKey,
295-
spaceId: String
289+
key: AnalyticsRelationKey
296290
) {
297291
logEvent(
298292
isEmpty ? "DeleteRelationValue" : "ChangeRelationValue",
299-
spaceId: spaceId,
300293
withEventProperties: [
301294
AnalyticsEventsPropertiesKey.type: type.rawValue,
302295
AnalyticsEventsPropertiesKey.format: format.analyticsName,
@@ -317,29 +310,27 @@ extension AnytypeAnalytics {
317310
logEvent("CreateObject", spaceId: spaceId, withEventProperties: properties)
318311
}
319312

320-
func logCreateObjectType(spaceId: String) {
313+
func logCreateObjectType() {
321314
let properties = [
322315
AnalyticsEventsPropertiesKey.objectType: "_otobjectType",
323316
AnalyticsEventsPropertiesKey.format: "Page"
324317
]
325-
logEvent("CreateObject", spaceId: spaceId, withEventProperties: properties)
318+
logEvent("CreateObject", withEventProperties: properties)
326319
}
327320

328-
func logLinkToObject(type: AnalyticsEventsLinkToObjectType, spaceId: String) {
321+
func logLinkToObject(type: AnalyticsEventsLinkToObjectType) {
329322
logEvent(
330323
"LinkToObject",
331-
spaceId: spaceId,
332324
withEventProperties: [
333325
AnalyticsEventsPropertiesKey.linkType: type.rawValue
334326
]
335327
)
336328
}
337329

338330
// MARK: - Collection
339-
func logScreenCollection(with type: String, spaceId: String) {
331+
func logScreenCollection(with type: String) {
340332
logEvent(
341333
"ScreenCollection",
342-
spaceId: spaceId,
343334
withEventProperties: [
344335
AnalyticsEventsPropertiesKey.embedType: AnalyticsEventsSetCollectionEmbedType.object,
345336
AnalyticsEventsPropertiesKey.type: type
@@ -349,10 +340,9 @@ extension AnytypeAnalytics {
349340

350341
// MARK: - Type
351342

352-
func logScreenType(objectType: AnalyticsObjectType?, spaceId: String) {
343+
func logScreenType(objectType: AnalyticsObjectType?) {
353344
logEvent(
354345
"ScreenType",
355-
spaceId: spaceId,
356346
withEventProperties: [
357347
AnalyticsEventsPropertiesKey.objectType: objectType?.analyticsId ?? ""
358348
]
@@ -389,10 +379,9 @@ extension AnytypeAnalytics {
389379
}
390380

391381
// MARK: - Set
392-
func logScreenSet(with type: String, spaceId: String) {
382+
func logScreenSet(with type: String) {
393383
logEvent(
394384
"ScreenSet",
395-
spaceId: spaceId,
396385
withEventProperties: [
397386
AnalyticsEventsPropertiesKey.embedType: AnalyticsEventsSetCollectionEmbedType.object,
398387
AnalyticsEventsPropertiesKey.type: type
@@ -686,29 +675,26 @@ extension AnytypeAnalytics {
686675
logEvent("SettingsWallpaperSet")
687676
}
688677

689-
func logScreenSearch(spaceId: String, type: ScreenSearchType) {
678+
func logScreenSearch(type: ScreenSearchType) {
690679
logEvent(
691680
"ScreenSearch",
692-
spaceId: spaceId,
693681
withEventProperties: [
694682
AnalyticsEventsPropertiesKey.type: type.rawValue
695683
])
696684
}
697685

698-
func logSearchResult(spaceId: String, objectType: String? = nil) {
686+
func logSearchResult(objectType: String? = nil) {
699687
logEvent(
700688
"SearchResult",
701-
spaceId: spaceId,
702689
withEventProperties: [
703690
AnalyticsEventsPropertiesKey.objectType: objectType
704691
].compactMapValues { $0 }
705692
)
706693
}
707694

708-
func logSearchInput(spaceId: String, route: SearchInputRoute? = nil) {
695+
func logSearchInput(route: SearchInputRoute? = nil) {
709696
logEvent(
710697
"SearchInput",
711-
spaceId: spaceId,
712698
withEventProperties: [
713699
AnalyticsEventsPropertiesKey.route: route?.rawValue
714700
].compactMapValues { $0 }
@@ -749,23 +735,22 @@ extension AnytypeAnalytics {
749735
)
750736
}
751737

752-
func logDuplicateObject(count: Int, objectType: AnalyticsObjectType, spaceId: String) {
738+
func logDuplicateObject(count: Int, objectType: AnalyticsObjectType) {
753739
logEvent(
754740
"DuplicateObject",
755-
spaceId: spaceId,
756741
withEventProperties: [
757742
AnalyticsEventsPropertiesKey.count: count,
758743
AnalyticsEventsPropertiesKey.objectType: objectType.analyticsId,
759744
]
760745
)
761746
}
762747

763-
func logCopyBlock(spaceId: String, countBlocks: Int) {
764-
logEvent("CopyBlock", spaceId: spaceId, withEventProperties: [AnalyticsEventsPropertiesKey.count: countBlocks])
748+
func logCopyBlock(countBlocks: Int) {
749+
logEvent("CopyBlock", withEventProperties: [AnalyticsEventsPropertiesKey.count: countBlocks])
765750
}
766751

767-
func logPasteBlock(spaceId: String, countBlocks: Int) {
768-
logEvent("PasteBlock", spaceId: spaceId, withEventProperties: [AnalyticsEventsPropertiesKey.count: countBlocks])
752+
func logPasteBlock(countBlocks: Int) {
753+
logEvent("PasteBlock", withEventProperties: [AnalyticsEventsPropertiesKey.count: countBlocks])
769754
}
770755

771756
func logSetObjectDescription() {
@@ -930,10 +915,9 @@ extension AnytypeAnalytics {
930915
)
931916
}
932917

933-
func logTemplateCreate(objectType: AnalyticsObjectType, spaceId: String) {
918+
func logTemplateCreate(objectType: AnalyticsObjectType) {
934919
logEvent(
935920
"CreateTemplate",
936-
spaceId: spaceId,
937921
withEventProperties: [
938922
AnalyticsEventsPropertiesKey.objectType: objectType.analyticsId
939923
]
@@ -970,10 +954,9 @@ extension AnytypeAnalytics {
970954
)
971955
}
972956

973-
func logCreateLink(spaceId: String, objectType: AnalyticsObjectType, route: AnalyticsEventsRouteKind) {
957+
func logCreateLink(objectType: AnalyticsObjectType, route: AnalyticsEventsRouteKind) {
974958
logEvent(
975959
"CreateLink",
976-
spaceId: spaceId,
977960
withEventProperties: [
978961
AnalyticsEventsPropertiesKey.objectType: objectType.analyticsId,
979962
AnalyticsEventsPropertiesKey.route: route.rawValue
@@ -1070,6 +1053,7 @@ extension AnytypeAnalytics {
10701053
func logGalleryInstall(name: String) {
10711054
logEvent(
10721055
"GalleryInstall",
1056+
addActiveSpaceInfo: false,
10731057
withEventProperties: [AnalyticsEventsPropertiesKey.name: name]
10741058
)
10751059
}
@@ -1196,12 +1180,12 @@ extension AnytypeAnalytics {
11961180
logEvent("ScreenSettingsSpaceMembers", withEventProperties: [AnalyticsEventsPropertiesKey.route: route.rawValue])
11971181
}
11981182

1199-
func logDuplicateBlock(spaceId: String) {
1200-
logEvent("DuplicateBlock", spaceId: spaceId)
1183+
func logDuplicateBlock() {
1184+
logEvent("DuplicateBlock")
12011185
}
12021186

1203-
func logDeleteRelation(spaceId: String, format: PropertyFormat, key: AnalyticsRelationKey? = nil, route: DeleteRelationRoute) {
1204-
logEvent("DeleteRelation", spaceId: spaceId, withEventProperties: [
1187+
func logDeleteRelation(format: PropertyFormat, key: AnalyticsRelationKey? = nil, route: DeleteRelationRoute) {
1188+
logEvent("DeleteRelation", withEventProperties: [
12051189
AnalyticsEventsPropertiesKey.relationKey: key?.value ?? "",
12061190
AnalyticsEventsPropertiesKey.format: format.analyticsName,
12071191
AnalyticsEventsPropertiesKey.route: route.rawValue

Anytype/Sources/Analytics/AnytypeAnalytics/AnytypeAnalytics.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ final class AnytypeAnalytics: @unchecked Sendable {
2828

2929
@Injected(\.participantSpacesStorage)
3030
private var participantSpacesStorage: any ParticipantSpacesStorageProtocol
31+
@Injected(\.activeSpaceManager)
32+
private var activeSpaceManager: any ActiveSpaceManagerProtocol
3133

3234
private init() {
3335
userProperties[Keys.interfaceLang] = Locale.current.language.languageCode?.identifier
@@ -99,10 +101,20 @@ final class AnytypeAnalytics: @unchecked Sendable {
99101
eventProperties[AnalyticsEventsPropertiesKey.uxType] = uxType
100102
}
101103

102-
logEvent(eventType, withEventProperties: eventProperties)
104+
logRawEvent(eventType, withEventProperties: eventProperties)
103105
}
104106

105-
func logEvent(_ eventType: String, withEventProperties eventProperties: [String : Any] = [:]) {
107+
func logEvent(_ eventType: String, addActiveSpaceInfo: Bool = true, withEventProperties eventProperties: [String : Any] = [:]) {
108+
if addActiveSpaceInfo, let workspaceInfo = activeSpaceManager.workspaceInfo {
109+
logEvent(eventType, spaceId: workspaceInfo.accountSpaceId, withEventProperties: eventProperties)
110+
} else {
111+
logRawEvent(eventType, withEventProperties: eventProperties)
112+
}
113+
}
114+
115+
// MARK: - Private
116+
117+
private func logRawEvent(_ eventType: String, withEventProperties eventProperties: [String : Any] = [:]) {
106118
let eventConfiguration = eventsConfiguration[eventType]
107119

108120
if case .notInRow = eventConfiguration?.threshold, lastEvents == eventType {

Anytype/Sources/PresentationLayer/Common/SwiftUI/PropertyDetailsViews/Date/PropertyCalendarViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ final class PropertyCalendarViewModel: ObservableObject {
5454
isEmpty: value.isZero,
5555
format: relationDetails.format,
5656
type: config.analyticsType,
57-
key: relationDetails.analyticsKey,
58-
spaceId: config.spaceId
57+
key: relationDetails.analyticsKey
5958
)
6059
}
6160
}

Anytype/Sources/PresentationLayer/Common/SwiftUI/PropertyDetailsViews/PropertySelectedOptions/PropertySelectedOptionsModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ final class PropertySelectedOptionsModel: PropertySelectedOptionsModelProtocol {
8383
isEmpty: selectedOptionsIds.isEmpty,
8484
format: relationDetails.format,
8585
type: config.analyticsType,
86-
key: relationDetails.analyticsKey,
87-
spaceId: config.spaceId
86+
key: relationDetails.analyticsKey
8887
)
8988
}
9089
}

Anytype/Sources/PresentationLayer/Common/SwiftUI/PropertyDetailsViews/Text/TextPropertyEditingViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ final class TextPropertyEditingViewModel: ObservableObject {
120120
isEmpty: text.isEmpty,
121121
format: relationDetails.format,
122122
type: config.analyticsType,
123-
key: relationDetails.analyticsKey,
124-
spaceId: config.spaceId
123+
key: relationDetails.analyticsKey
125124
)
126125
}
127126
}

Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/GlobalSearchViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class GlobalSearchViewModel: ObservableObject {
8080
}
8181

8282
func onSearchTextChanged() {
83-
AnytypeAnalytics.instance().logSearchInput(spaceId: moduleData.spaceId)
83+
AnytypeAnalytics.instance().logSearchInput()
8484
}
8585

8686
func onKeyboardButtonTap() {
@@ -89,7 +89,7 @@ final class GlobalSearchViewModel: ObservableObject {
8989
}
9090

9191
func onSelect(searchData: SearchWithMetaModel) {
92-
AnytypeAnalytics.instance().logSearchResult(spaceId: moduleData.spaceId, objectType: state.section.analyticsValue)
92+
AnytypeAnalytics.instance().logSearchResult(objectType: state.section.analyticsValue)
9393
dismiss.toggle()
9494
moduleData.onSelect(searchData.editorScreenData)
9595
}
@@ -141,12 +141,12 @@ final class GlobalSearchViewModel: ObservableObject {
141141
private func restoreState() {
142142
let restoredState = globalSearchSavedStatesService.restoreState(for: moduleData.spaceId)
143143
guard let restoredState else {
144-
AnytypeAnalytics.instance().logScreenSearch(spaceId: moduleData.spaceId, type: .empty)
144+
AnytypeAnalytics.instance().logScreenSearch(type: .empty)
145145
return
146146
}
147147
state = restoredState
148148
if restoredState.searchText.isNotEmpty {
149-
AnytypeAnalytics.instance().logScreenSearch(spaceId: moduleData.spaceId, type: .saved)
149+
AnytypeAnalytics.instance().logScreenSearch(type: .saved)
150150
}
151151
}
152152

Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchWithMeta/ObjectSearchWithMetaViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ final class ObjectSearchWithMetaViewModel: ObservableObject {
5252
sections = []
5353
}
5454

55-
AnytypeAnalytics.instance().logSearchInput(spaceId: moduleData.spaceId)
55+
AnytypeAnalytics.instance().logSearchInput()
5656
}
5757

5858
func onSelect(searchData: SearchWithMetaModel) {

Anytype/Sources/PresentationLayer/FileDownloading flow/FileDownloadingCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension FileDownloadingCoordinator: FileDownloadingModuleOutput {
4040

4141
func didDownloadFileTo(_ url: URL) {
4242
type.flatMap {
43-
AnytypeAnalytics.instance().logDownloadMedia(type: $0, spaceId: spaceId)
43+
AnytypeAnalytics.instance().logDownloadMedia(type: $0)
4444
}
4545
viewController?.topPresentedController.dismiss(animated: true) { [weak self] in
4646
self?.showDocumentPickerViewController(url: url)

Anytype/Sources/PresentationLayer/Modules/CreateObjectType/CreateObjectTypeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class CreateObjectTypeViewModel: ObservableObject {
2121
Task {
2222
let type = try await typesService.createType(name: info.singularName, pluralName: info.pluralName, icon: info.icon, color: info.color, spaceId: data.spaceId)
2323

24-
AnytypeAnalytics.instance().logCreateObjectType(spaceId: data.spaceId)
24+
AnytypeAnalytics.instance().logCreateObjectType()
2525

2626
completion?(type)
2727
}

Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ final class SetObjectCreationSettingsViewModel: ObservableObject {
9595
guard let self else { return }
9696
do {
9797
let templateId = try await templatesService.createTemplateFromObjectType(objectTypeId: objectTypeId, spaceId: spaceId)
98-
AnytypeAnalytics.instance().logTemplateCreate(objectType: .object(typeId: objectTypeId), spaceId: spaceId)
98+
AnytypeAnalytics.instance().logTemplateCreate(objectType: .object(typeId: objectTypeId))
9999
output?.templateEditingHandler(
100100
setting: ObjectCreationSetting(objectTypeId: objectTypeId, spaceId: spaceId, templateId: templateId),
101101
onSetAsDefaultTemplate: { [weak self] templateId in

0 commit comments

Comments
 (0)