From d15d0e0070c3286cb81a5601ae722ce5e597b6e4 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Wed, 5 Jul 2023 12:54:03 +0200 Subject: [PATCH] Add location related analytics (#1241) * Refactor trackComposer method * Track location screen * Refactor isPinDropSharing -> isSharingUserLocation * Add trackComposer event * Fix UTs * Cleanup * Add AnalyticsLocationType --- ElementX.xcodeproj/project.pbxproj | 22 ++++++++----- .../xcshareddata/swiftpm/Package.resolved | 4 +-- .../RoomFlowCoordinator.swift | 10 ++++-- .../LocationSharingScreenModels.swift | 16 ++++----- .../StaticLocationScreenCoordinator.swift | 6 ++-- .../StaticLocationScreenViewModel.swift | 4 +-- .../View/StaticLocationScreen.swift | 5 +-- .../Analytics/AnalyticsLocationType.swift | 33 +++++++++++++++++++ .../Services/Analytics/AnalyticsScreen.swift | 6 ++++ .../Services/Analytics/AnalyticsService.swift | 14 ++++++-- .../StaticLocationScreenViewModelTests.swift | 6 ++-- project.yml | 2 +- 12 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 ElementX/Sources/Services/Analytics/AnalyticsLocationType.swift diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 7b5338b88..cee663bb2 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 1FEC0A4EC6E6DF693C16B32A /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CEBCB9676FCD1D0F13188DD /* StringTests.swift */; }; 206F0DBAB6AF042CA1FF2C0D /* SettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D487C1185D658F8B15B8F55 /* SettingsViewModelTests.swift */; }; 208C19811613F9A10F8A7B75 /* MediaLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AFCE895ECFFA53FEE64D62B /* MediaLoader.swift */; }; + 2198B4458AFF69102BBCC370 /* RoomTimelineItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA7D3C686C214470F4911618 /* RoomTimelineItemViewModel.swift */; }; 21BF2B7CEDFE3CA67C5355AD /* test_image.png in Resources */ = {isa = PBXBuildFile; fileRef = C733D11B421CFE3A657EF230 /* test_image.png */; }; 22882C710BC99EC34A5024A0 /* UITestsScreenIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEBE5EA91E8691EDF364EC2 /* UITestsScreenIdentifier.swift */; }; 2352C541AF857241489756FF /* MockRoomSummaryProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F7D42E66E939B709C1EC390 /* MockRoomSummaryProvider.swift */; }; @@ -439,6 +440,7 @@ 9EBDC79CAC9B63A0D626E333 /* LegalInformationScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB2CAA266B921D128C35710 /* LegalInformationScreenCoordinator.swift */; }; 9F19096BFA629C0AC282B1E4 /* CreateRoomScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8CEB4634C0DD7779C4AB504 /* CreateRoomScreenUITests.swift */; }; 9FAF6DA7E8E85C9699757764 /* CollapsibleRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2656184491C505700D2405 /* CollapsibleRoomTimelineView.swift */; }; + A002DDF12A557DFF00228A9F /* AnalyticsLocationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A002DDF02A557DFF00228A9F /* AnalyticsLocationType.swift */; }; A009BDFB0A6816D4C392ADCB /* SettingsScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AF715D4FD4710EBB637D661 /* SettingsScreenViewModelProtocol.swift */; }; A021827B528F1EDC9101CA58 /* AppCoordinatorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBC776F301D374A3298C69DA /* AppCoordinatorProtocol.swift */; }; A0A0D2A9564BDA3FDE2E360F /* FormattedBodyText.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73FF1A33198F5FAE9D34B1F /* FormattedBodyText.swift */; }; @@ -464,7 +466,6 @@ A680F54935A6ADEA4ED6C38F /* TimelineItemStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A4C9547BBFEEF30AA11329B /* TimelineItemStatusView.swift */; }; A6D4C5EEA85A6A0ABA1559D6 /* RoomDetailsEditScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D09C79746BDCD9173EB3A7 /* RoomDetailsEditScreenModels.swift */; }; A6DEC1ADEC8FEEC206A0FA37 /* AttributedStringBuilderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72F37B5DA798C9AE436F2C2C /* AttributedStringBuilderProtocol.swift */; }; - A72F51AB2A54364E0038A02F /* RoomTimelineItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A72F51AA2A54364E0038A02F /* RoomTimelineItemViewModel.swift */; }; A74438ED16F8683A4B793E6A /* AnalyticsSettingsScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BCE3FAF40932AC7C7639AC4 /* AnalyticsSettingsScreenViewModel.swift */; }; A7D48E44D485B143AADDB77D /* Strings+Untranslated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A18F6CE4D694D21E4EA9B25 /* Strings+Untranslated.swift */; }; A7FD7B992E6EE6E5A8429197 /* RoomSummaryDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 142808B69851451AC32A2CEA /* RoomSummaryDetails.swift */; }; @@ -483,6 +484,7 @@ AC7AA215D60FBC307F984028 /* Consumable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 127A57D053CE8C87B5EFB089 /* Consumable.swift */; }; ACF094CF3BF02DBFA6DFDE60 /* AuthenticationCoordinatorUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D2D0A6F1ABC99D29462FB84 /* AuthenticationCoordinatorUITests.swift */; }; AD2A81B65A9F6163012086F1 /* MXLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 111B698739E3410E2CDB7144 /* MXLog.swift */; }; + AD55E245FE686D7DB4C86406 /* RoomTimelineItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90F2F8998E5632668B0AD848 /* RoomTimelineItemView.swift */; }; AE1160076F663BF14E0E893A /* EffectsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4548A9BDE5CB3AB864BCA9F /* EffectsView.swift */; }; AE1A73B24D63DA3D63DC4EE3 /* SessionVerificationControllerProxyMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 248649EBA5BC33DB93698734 /* SessionVerificationControllerProxyMock.swift */; }; AF19D65A9C60C6B2646F3210 /* RedactedRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6E6BDF9D26DB05C88901416 /* RedactedRoomTimelineItem.swift */; }; @@ -588,7 +590,6 @@ CEB8FB1269DE20536608B957 /* LoginMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B41FABA2B0AEF4389986495 /* LoginMode.swift */; }; CF3827071B0BC9638BD44F5D /* WaitlistScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB58EF0176D4CFB1040DA22 /* WaitlistScreenViewModel.swift */; }; CF4044A8EED5C41BC0ED6ABE /* SoftLogoutScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D316BB02636AF2174F2580E6 /* SoftLogoutScreenViewModelProtocol.swift */; }; - CF82143AA4A4F7BD11D22946 /* RoomTimelineItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACB6C5E4950B6C9842F35A38 /* RoomTimelineItemView.swift */; }; D02AA6208C7ACB9BE6332394 /* UNNotificationContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE148A4FFEE853C5A281500C /* UNNotificationContent.swift */; }; D181AC8FF236B7F91C0A8C28 /* MapTiler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23AA3F4B285570805CB0CCDD /* MapTiler.swift */; }; D2A15D03F81342A09340BD56 /* AnalyticsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEFEEE93B82937B2E86F92EB /* AnalyticsScreen.swift */; }; @@ -1136,6 +1137,7 @@ 8FC26871038FB0E4AAE22605 /* apple_emojis_data.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = apple_emojis_data.json; sourceTree = ""; }; 8FC803282F9268D49F4ABF14 /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 90A55430639712CFACA34F43 /* TextRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineItem.swift; sourceTree = ""; }; + 90F2F8998E5632668B0AD848 /* RoomTimelineItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemView.swift; sourceTree = ""; }; 923485F85E1D765EF9D20E88 /* UserProfileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfileCell.swift; sourceTree = ""; }; 92390F9FA98255440A6BF5F8 /* OIDCAuthenticationPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OIDCAuthenticationPresenter.swift; sourceTree = ""; }; 92FCD9116ADDE820E4E30F92 /* UIKitBackgroundTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitBackgroundTask.swift; sourceTree = ""; }; @@ -1170,6 +1172,7 @@ 9CE3C90E487B255B735D73C8 /* RoomScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomScreenViewModel.swift; sourceTree = ""; }; 9E6D88E8AFFBF2C1D589C0FA /* UIConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIConstants.swift; sourceTree = ""; }; 9F85164F9475FF2867F71AAA /* RoomTimelineController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineController.swift; sourceTree = ""; }; + A002DDF02A557DFF00228A9F /* AnalyticsLocationType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsLocationType.swift; sourceTree = ""; }; A00C7A331B72C0F05C00392F /* RoomScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomScreenViewModelProtocol.swift; sourceTree = ""; }; A05707BF550D770168A406DB /* LoginViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModelTests.swift; sourceTree = ""; }; A057F2FDC14866C3026A89A4 /* NotificationManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManagerProtocol.swift; sourceTree = ""; }; @@ -1190,7 +1193,6 @@ A58E93D91DE3288010390DEE /* EmojiDetectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiDetectionTests.swift; sourceTree = ""; }; A65F140F9FE5E8D4DAEFF354 /* RoomProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomProxy.swift; sourceTree = ""; }; A6B891A6DA826E2461DBB40F /* PHGPostHogConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PHGPostHogConfiguration.swift; sourceTree = ""; }; - A72F51AA2A54364E0038A02F /* RoomTimelineItemViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemViewModel.swift; sourceTree = ""; }; A73A07BAEDD74C48795A996A /* AsyncSequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncSequence.swift; sourceTree = ""; }; A7C4EA55DA62F9D0F984A2AE /* CollapsibleTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsibleTimelineItem.swift; sourceTree = ""; }; A861DA5932B128FE1DCB5CE2 /* InviteUsersScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteUsersScreenCoordinator.swift; sourceTree = ""; }; @@ -1207,7 +1209,6 @@ ABA4CF2F5B4F68D02E412004 /* ServerConfirmationScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerConfirmationScreenViewModelProtocol.swift; sourceTree = ""; }; AC1DA29A5A041CC0BACA7CB0 /* MockImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockImageCache.swift; sourceTree = ""; }; AC3F82523D6F48B926D6AF68 /* AppSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = ""; }; - ACB6C5E4950B6C9842F35A38 /* RoomTimelineItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemView.swift; sourceTree = ""; }; ACCC1874C122E2BBE648B8F5 /* LegalInformationScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegalInformationScreenUITests.swift; sourceTree = ""; }; AD378D580A41E42560C60E9C /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/Localizable.strings; sourceTree = ""; }; ADB35E2DB4EFE8E6F3959629 /* InviteUsersScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteUsersScreenUITests.swift; sourceTree = ""; }; @@ -1415,6 +1416,7 @@ F9212AE02CBDD692C56A879F /* TimelineTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineTableViewController.swift; sourceTree = ""; }; F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineView.swift; sourceTree = ""; }; F9ED8E731E21055F728E5FED /* TimelineStartRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineStartRoomTimelineView.swift; sourceTree = ""; }; + FA7D3C686C214470F4911618 /* RoomTimelineItemViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemViewModel.swift; sourceTree = ""; }; FB0D6CB491777E7FC6B5BA12 /* CreateRoomScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateRoomScreen.swift; sourceTree = ""; }; FB7BAD55A4E2B8E5828CD64C /* SoftLogoutScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoftLogoutScreenViewModel.swift; sourceTree = ""; }; FBC776F301D374A3298C69DA /* AppCoordinatorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinatorProtocol.swift; sourceTree = ""; }; @@ -2069,6 +2071,7 @@ E3B97591B2D3D4D67553506D /* AnalyticsClientProtocol.swift */, D77B3D4950F1707E66E4A45A /* AnalyticsConfiguration.swift */, 57B6B383F1FD04CC0E7B60C6 /* AnalyticsConsentState.swift */, + A002DDF02A557DFF00228A9F /* AnalyticsLocationType.swift */, FEFEEE93B82937B2E86F92EB /* AnalyticsScreen.swift */, 5445FCE0CE15E634FDC1A2E2 /* AnalyticsService.swift */, A6B891A6DA826E2461DBB40F /* PHGPostHogConfiguration.swift */, @@ -2780,9 +2783,9 @@ 8D55702474F279D910D2D162 /* RoomStateEventStringBuilder.swift */, 105B2A8426404EF66F00CFDB /* RoomTimelineItemFactory.swift */, 7D25A35764C7B3DB78954AB5 /* RoomTimelineItemFactoryProtocol.swift */, - A72F51AA2A54364E0038A02F /* RoomTimelineItemViewModel.swift */, ED1D792EB82506A19A72C8DE /* RoomTimelineItemProtocol.swift */, - ACB6C5E4950B6C9842F35A38 /* RoomTimelineItemView.swift */, + 90F2F8998E5632668B0AD848 /* RoomTimelineItemView.swift */, + FA7D3C686C214470F4911618 /* RoomTimelineItemViewModel.swift */, 75D1D02F7F3AC1122FCFB4F3 /* Items */, ); path = TimelineItems; @@ -4264,7 +4267,6 @@ 0C58A846F61949B1D545D661 /* NoticeRoomTimelineItem.swift in Sources */, 9408CE8B8865C0C8DD4C9869 /* NoticeRoomTimelineItemContent.swift in Sources */, 368C8758FCD079E6AAA18C2C /* NoticeRoomTimelineView.swift in Sources */, - A72F51AB2A54364E0038A02F /* RoomTimelineItemViewModel.swift in Sources */, 3F70E237CE4C3FAB02FC227F /* NotificationConstants.swift in Sources */, CE9530A4CA661E090635C2F2 /* NotificationItemProxy.swift in Sources */, 652ACCF104A8CEF30788963C /* NotificationManager.swift in Sources */, @@ -4298,6 +4300,7 @@ 46A261AA898344A1F3C406B1 /* ReportContentScreenModels.swift in Sources */, 42A5A42ACF063EEE6B1980D2 /* ReportContentScreenViewModel.swift in Sources */, 8285FF4B2C2331758C437FF7 /* ReportContentScreenViewModelProtocol.swift in Sources */, + A002DDF12A557DFF00228A9F /* AnalyticsLocationType.swift in Sources */, A494741843F087881299ACF0 /* RestorationToken.swift in Sources */, 755EE5B0998C6A4D764D86E5 /* RoomAttachmentPicker.swift in Sources */, 0BDA19079FD6E17C5AC62E22 /* RoomDetailsEditScreen.swift in Sources */, @@ -4349,9 +4352,10 @@ 70558528EF68CAAEF09972D5 /* RoomTimelineItemFixtures.swift in Sources */, 878070573C7BF19E735707B4 /* RoomTimelineItemProperties.swift in Sources */, 1AE4AEA0FA8DEF52671832E0 /* RoomTimelineItemProtocol.swift in Sources */, + AD55E245FE686D7DB4C86406 /* RoomTimelineItemView.swift in Sources */, + 2198B4458AFF69102BBCC370 /* RoomTimelineItemViewModel.swift in Sources */, 9BD3A773186291560DF92B62 /* RoomTimelineProvider.swift in Sources */, 77D7DAA41AAB36800C1F2E2D /* RoomTimelineProviderProtocol.swift in Sources */, - CF82143AA4A4F7BD11D22946 /* RoomTimelineItemView.swift in Sources */, B2F8E01ABA1BA30265B4ECBE /* RoundedCornerShape.swift in Sources */, 50C90117FE25390BFBD40173 /* RustTracing.swift in Sources */, D43F0503EF2CBC55272538FE /* SDKGeneratedMocks.swift in Sources */, @@ -5191,7 +5195,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-analytics-events"; requirement = { kind = upToNextMinorVersion; - minimumVersion = 0.5.0; + minimumVersion = 0.6.0; }; }; C13F55E4518415CB4C278E73 /* XCRemoteSwiftPackageReference "DTCoreText" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 39830ac13..4d9210683 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -102,8 +102,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-analytics-events", "state" : { - "revision" : "2f5fa5f1e2f6c6ae1a47c33d953a3ce289167eb0", - "version" : "0.5.0" + "revision" : "42b2faa417c1e95f430bf8f6e379adba25ad5ef8", + "version" : "0.6.0" } }, { diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index 5bd30dc4a..50b401bcf 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -511,15 +511,21 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { coordinator.actions.sink { [weak self] action in guard let self else { return } switch action { - case .selectedLocation(let geoURI): + case .selectedLocation(let geoURI, let isUserLocation): Task { _ = await self.roomProxy?.sendLocation(body: geoURI.bodyMessage, geoURI: geoURI, description: nil, zoomLevel: nil, - assetType: .pin) + assetType: isUserLocation ? .sender : .pin) self.navigationSplitCoordinator.setSheetCoordinator(nil) } + + self.analytics.trackComposer(inThread: false, + isEditing: false, + isReply: false, + locationType: isUserLocation ? .myLocation : .pin, + startsThread: nil) case .close: self.navigationSplitCoordinator.setSheetCoordinator(nil) } diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift index 52df3f948..609347e5b 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift @@ -24,7 +24,7 @@ enum LocationSharingViewError: Error, Hashable { enum StaticLocationScreenViewModelAction { case close - case sendLocation(GeoURI) + case sendLocation(GeoURI, isUserLocation: Bool) } enum StaticLocationInteractionMode: Hashable { @@ -33,9 +33,9 @@ enum StaticLocationInteractionMode: Hashable { } struct StaticLocationScreenViewState: BindableState { - init(interactionMode: StaticLocationInteractionMode, isPinDropSharing: Bool = true, showsUserLocationMode: ShowUserLocationMode = .hide) { + init(interactionMode: StaticLocationInteractionMode, isSharingUserLocation: Bool = false, showsUserLocationMode: ShowUserLocationMode = .hide) { self.interactionMode = interactionMode - self.isPinDropSharing = isPinDropSharing + self.isSharingUserLocation = isSharingUserLocation self.showsUserLocationMode = showsUserLocationMode switch interactionMode { @@ -47,10 +47,10 @@ struct StaticLocationScreenViewState: BindableState { } let interactionMode: StaticLocationInteractionMode - /// Indicates whether the user has moved around the map to drop a pin somewhere other than their current location - var isPinDropSharing = true + /// Indicates whether the user is sharing his current location + var isSharingUserLocation: Bool /// Behavior mode of the current user's location, can be hidden, only shown and shown following the user - var showsUserLocationMode: ShowUserLocationMode = .hide + var showsUserLocationMode: ShowUserLocationMode var bindings = StaticLocationScreenBindings() @@ -67,10 +67,10 @@ struct StaticLocationScreenViewState: BindableState { } } - var showPinInTheCenter: Bool { + var isLocationPickerMode: Bool { switch interactionMode { case .picker: - return isPinDropSharing + return true case .viewOnly: return false } diff --git a/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenCoordinator.swift b/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenCoordinator.swift index a160bb8aa..abb36812f 100644 --- a/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenCoordinator.swift +++ b/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenCoordinator.swift @@ -23,7 +23,7 @@ struct StaticLocationScreenCoordinatorParameters { enum StaticLocationScreenCoordinatorAction { case close - case selectedLocation(GeoURI) + case selectedLocation(GeoURI, isUserLocation: Bool) } final class StaticLocationScreenCoordinator: CoordinatorProtocol { @@ -51,8 +51,8 @@ final class StaticLocationScreenCoordinator: CoordinatorProtocol { switch action { case .close: actionsSubject.send(.close) - case .sendLocation(let geoURI): - actionsSubject.send(.selectedLocation(geoURI)) + case .sendLocation(let geoURI, let isUserLocation): + actionsSubject.send(.selectedLocation(geoURI, isUserLocation: isUserLocation)) } } .store(in: &cancellables) diff --git a/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenViewModel.swift b/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenViewModel.swift index 4776fe19f..f6dab2e5f 100644 --- a/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenViewModel.swift +++ b/ElementX/Sources/Screens/LocationSharing/StaticLocationScreenViewModel.swift @@ -36,10 +36,10 @@ class StaticLocationScreenViewModel: StaticLocationScreenViewModelType, StaticLo actionsSubject.send(.close) case .selectLocation: guard let coordinate = state.bindings.mapCenterLocation else { return } - actionsSubject.send(.sendLocation(.init(coordinate: coordinate))) + actionsSubject.send(.sendLocation(.init(coordinate: coordinate), isUserLocation: state.isSharingUserLocation)) case .userDidPan: state.showsUserLocationMode = .hide - state.isPinDropSharing = true + state.isSharingUserLocation = false } } } diff --git a/ElementX/Sources/Screens/LocationSharing/View/StaticLocationScreen.swift b/ElementX/Sources/Screens/LocationSharing/View/StaticLocationScreen.swift index 291ce5fc2..f8a1fdfa6 100644 --- a/ElementX/Sources/Screens/LocationSharing/View/StaticLocationScreen.swift +++ b/ElementX/Sources/Screens/LocationSharing/View/StaticLocationScreen.swift @@ -33,6 +33,7 @@ struct StaticLocationScreen: View { } mapView } + .track(screen: context.viewState.isLocationPickerMode ? .locationSend : .locationView) .navigationTitle(context.viewState.navigationTitle) .navigationBarTitleDisplayMode(.inline) .toolbar { toolbar } @@ -49,7 +50,7 @@ struct StaticLocationScreen: View { userDidPan: { context.send(viewAction: .userDidPan) }) - if context.viewState.showPinInTheCenter { + if context.viewState.isLocationPickerMode { LocationMarkerView() } } @@ -105,7 +106,7 @@ struct StaticLocationScreen: View { .resizable() .aspectRatio(contentMode: .fit) .frame(width: shareMarkerSize, height: shareMarkerSize) - Text(context.viewState.isPinDropSharing ? L10n.screenShareThisLocationAction : L10n.screenShareMyLocationAction) + Text(context.viewState.isSharingUserLocation ? L10n.screenShareMyLocationAction : L10n.screenShareThisLocationAction) } } } diff --git a/ElementX/Sources/Services/Analytics/AnalyticsLocationType.swift b/ElementX/Sources/Services/Analytics/AnalyticsLocationType.swift new file mode 100644 index 000000000..1390b36e3 --- /dev/null +++ b/ElementX/Sources/Services/Analytics/AnalyticsLocationType.swift @@ -0,0 +1,33 @@ +// +// Copyright 2023 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import AnalyticsEvents + +enum AnalyticsLocationType { + case myLocation + case pin +} + +extension AnalyticsEvent.Composer.LocationType { + init(_ analyticsLocationType: AnalyticsLocationType) { + switch analyticsLocationType { + case .myLocation: + self = .MyLocation + case .pin: + self = .PinDrop + } + } +} diff --git a/ElementX/Sources/Services/Analytics/AnalyticsScreen.swift b/ElementX/Sources/Services/Analytics/AnalyticsScreen.swift index 174d4be40..831b70ff4 100644 --- a/ElementX/Sources/Services/Analytics/AnalyticsScreen.swift +++ b/ElementX/Sources/Services/Analytics/AnalyticsScreen.swift @@ -59,6 +59,8 @@ enum AnalyticsScreen: Int { case spaceBottomSheet case invites case createSpace + case locationSend + case locationView /// The screen name reported to the AnalyticsEvent. var screenName: AnalyticsEvent.MobileScreen.ScreenName { @@ -145,6 +147,10 @@ enum AnalyticsScreen: Int { return .Invites case .createSpace: return .CreateSpace + case .locationSend: + return .LocationSend + case .locationView: + return .LocationView } } } diff --git a/ElementX/Sources/Services/Analytics/AnalyticsService.swift b/ElementX/Sources/Services/Analytics/AnalyticsService.swift index a682665ba..68470b365 100644 --- a/ElementX/Sources/Services/Analytics/AnalyticsService.swift +++ b/ElementX/Sources/Services/Analytics/AnalyticsService.swift @@ -141,9 +141,19 @@ extension AnalyticsService { /// - inThread: whether the composer is used in a Thread /// - isEditing: whether the composer is used to edit a message /// - isReply: whether the composer is used to reply a message + /// - locationType: the type of the shared location /// - startsThread: whether the composer is used to start a new thread - func trackComposer(inThread: Bool, isEditing: Bool, isReply: Bool, startsThread: Bool?) { - capture(event: AnalyticsEvent.Composer(inThread: inThread, isEditing: isEditing, isReply: isReply, startsThread: startsThread)) + func trackComposer(inThread: Bool, + isEditing: Bool, + isReply: Bool, + locationType: AnalyticsLocationType? = nil, + startsThread: Bool?) { + capture(event: AnalyticsEvent.Composer(inThread: inThread, + isEditing: isEditing, + isLocation: locationType != nil, + isReply: isReply, + locationType: locationType.map { .init($0) }, + startsThread: startsThread)) } /// Track the presentation of a room diff --git a/UnitTests/Sources/StaticLocationScreenViewModelTests.swift b/UnitTests/Sources/StaticLocationScreenViewModelTests.swift index 79aa52f8f..057ec0db0 100644 --- a/UnitTests/Sources/StaticLocationScreenViewModelTests.swift +++ b/UnitTests/Sources/StaticLocationScreenViewModelTests.swift @@ -32,13 +32,13 @@ class StaticLocationScreenViewModelTests: XCTestCase { override func setUpWithError() throws { let viewModel = StaticLocationScreenViewModel(interactionMode: .picker) - viewModel.state.isPinDropSharing = false + viewModel.state.isSharingUserLocation = true self.viewModel = viewModel } func testUserDidPan() async throws { - XCTAssertFalse(context.viewState.isPinDropSharing) + XCTAssertTrue(context.viewState.isSharingUserLocation) context.send(viewAction: .userDidPan) - XCTAssertTrue(context.viewState.isPinDropSharing) + XCTAssertFalse(context.viewState.isSharingUserLocation) } } diff --git a/project.yml b/project.yml index 9f4e02c9c..41bf75954 100644 --- a/project.yml +++ b/project.yml @@ -60,7 +60,7 @@ packages: minorVersion: 1.0.0 AnalyticsEvents: url: https://github.com/matrix-org/matrix-analytics-events - minorVersion: 0.5.0 + minorVersion: 0.6.0 Collections: url: https://github.com/apple/swift-collections minorVersion: 1.0.0