diff --git a/AlphaWallet.xcodeproj/project.pbxproj b/AlphaWallet.xcodeproj/project.pbxproj index 1aa82cb25..c9424fd71 100644 --- a/AlphaWallet.xcodeproj/project.pbxproj +++ b/AlphaWallet.xcodeproj/project.pbxproj @@ -541,7 +541,6 @@ 5E7C7B2A4B7C94922DED2EA0 /* TokenCardRowViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C78CDFEB86A8356EA5818 /* TokenCardRowViewProtocol.swift */; }; 5E7C7B2C388D0B6E8AE1EED6 /* TransactionConfirmationRowDescriptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7919EE31DC0B8FCF0D40 /* TransactionConfirmationRowDescriptionView.swift */; }; 5E7C7B3027F3A56EF3EE5B7F /* EthCalllRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7ADC229B4038964F417C /* EthCalllRequest.swift */; }; - 5E7C7B371C9A7BEC46D8633D /* RemoteCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7DD30D23ACDDA7995355 /* RemoteCounter.swift */; }; 5E7C7B3E08EEA63C5B68B9C4 /* TokenCardRedemptionInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C778F20D32B70D7FF2135 /* TokenCardRedemptionInfoViewController.swift */; }; 5E7C7B414FA8A428798D73EF /* OpenSeaNonFungibleTokenHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C758EEBD945A3451C96C8 /* OpenSeaNonFungibleTokenHandling.swift */; }; 5E7C7B4778FF36371701242E /* BrowserHistoryViewControllerHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C79FA3E6A05845ECFCDCF /* BrowserHistoryViewControllerHeaderView.swift */; }; @@ -1686,7 +1685,6 @@ 5E7C7DC3AEBE4049927B7625 /* EnableServersHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnableServersHeaderView.swift; sourceTree = ""; }; 5E7C7DC4B06C1A623788EEED /* WalletConnectSessionCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletConnectSessionCellViewModel.swift; sourceTree = ""; }; 5E7C7DCB0BDDD30D10130AE7 /* GetIsERC875Encode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetIsERC875Encode.swift; sourceTree = ""; }; - 5E7C7DD30D23ACDDA7995355 /* RemoteCounter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteCounter.swift; sourceTree = ""; }; 5E7C7DD409C330DA4033F504 /* Keystore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Keystore.swift; sourceTree = ""; }; 5E7C7DD9C564F2C7DE435894 /* ConfirmSignMessageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfirmSignMessageTableViewCell.swift; sourceTree = ""; }; 5E7C7DDCCEDE8A14A9C49E4A /* TransactionRowViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionRowViewModel.swift; sourceTree = ""; }; @@ -3813,7 +3811,6 @@ isa = PBXGroup; children = ( 5E7C714BB4A095BE99B18F7A /* BlockscanChat.swift */, - 5E7C7DD30D23ACDDA7995355 /* RemoteCounter.swift */, ); path = BlockscanChat; sourceTree = ""; @@ -6621,7 +6618,6 @@ 5E7C78772A59685C37CB99C2 /* ToolsViewController.swift in Sources */, 5E7C76AFBBACDD13BEF25DA9 /* ToolsViewModel.swift in Sources */, 5E7C7126E01D824557FD7731 /* BlockscanChat.swift in Sources */, - 5E7C7B371C9A7BEC46D8633D /* RemoteCounter.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AlphaWallet/Analytics/Coordinators/AnalyticsCoordinator.swift b/AlphaWallet/Analytics/Coordinators/AnalyticsCoordinator.swift index 58278ce3e..8b13bdd3d 100644 --- a/AlphaWallet/Analytics/Coordinators/AnalyticsCoordinator.swift +++ b/AlphaWallet/Analytics/Coordinators/AnalyticsCoordinator.swift @@ -5,6 +5,7 @@ import Foundation protocol AnalyticsCoordinator { func log(navigation: AnalyticsNavigation, properties: [String: AnalyticsEventPropertyValue]?) func log(action: AnalyticsAction, properties: [String: AnalyticsEventPropertyValue]?) + func log(stat: AnalyticsStat, properties: [String: AnalyticsEventPropertyValue]?) func log(error: AnalyticsError, properties: [String: AnalyticsEventPropertyValue]?) func setUser(property: AnalyticsUserProperty, value: AnalyticsEventPropertyValue) func incrementUser(property: AnalyticsUserProperty, by value: Int) @@ -20,7 +21,11 @@ extension AnalyticsCoordinator { log(action: action, properties: nil) } + func log(stat: AnalyticsStat) { + log(stat: stat, properties: nil) + } + func log(error: AnalyticsError) { log(error: error, properties: nil) } -} +} \ No newline at end of file diff --git a/AlphaWallet/Analytics/Coordinators/AnalyticsService.swift b/AlphaWallet/Analytics/Coordinators/AnalyticsService.swift index 86c00fbd8..e399a4d93 100644 --- a/AlphaWallet/Analytics/Coordinators/AnalyticsService.swift +++ b/AlphaWallet/Analytics/Coordinators/AnalyticsService.swift @@ -68,6 +68,11 @@ class AnalyticsService: NSObject, AnalyticsServiceType { mixpanelService?.log(action: action, properties: properties) } + func log(stat: AnalyticsStat, properties: [String: AnalyticsEventPropertyValue]?) { + guard config.isSendAnalyticsEnabled else { return } + mixpanelService?.log(stat: stat, properties: properties) + } + func log(error: AnalyticsError, properties: [String: AnalyticsEventPropertyValue]?) { guard config.isSendAnalyticsEnabled else { return } mixpanelService?.log(error: error, properties: properties) diff --git a/AlphaWallet/Analytics/Coordinators/MixpanelCoordinator.swift b/AlphaWallet/Analytics/Coordinators/MixpanelCoordinator.swift index b479bc051..eec414e53 100644 --- a/AlphaWallet/Analytics/Coordinators/MixpanelCoordinator.swift +++ b/AlphaWallet/Analytics/Coordinators/MixpanelCoordinator.swift @@ -33,6 +33,11 @@ extension MixpanelCoordinator: AnalyticsCoordinator { mixpanelInstance.track(event: action.rawValue, properties: props) } + func log(stat: AnalyticsStat, properties: [String: AnalyticsEventPropertyValue]?) { + let props: Properties? = properties?.compactMapValues(convertParameterToSdkSpecificVersion) + mixpanelInstance.track(event: stat.rawValue, properties: props) + } + func log(error: AnalyticsError, properties: [String: AnalyticsEventPropertyValue]?) { let props: Properties? = properties?.compactMapValues(convertParameterToSdkSpecificVersion) mixpanelInstance.track(event: error.rawValue, properties: props) diff --git a/AlphaWallet/Analytics/Models/AnalyticsTypes.swift b/AlphaWallet/Analytics/Models/AnalyticsTypes.swift index 6b51bf939..61d2bd820 100644 --- a/AlphaWallet/Analytics/Models/AnalyticsTypes.swift +++ b/AlphaWallet/Analytics/Models/AnalyticsTypes.swift @@ -10,6 +10,10 @@ protocol AnalyticsAction { var rawValue: String { get } } +protocol AnalyticsStat { + var rawValue: String { get } +} + protocol AnalyticsError { var rawValue: String { get } } @@ -73,6 +77,11 @@ enum Analytics { case tapSafariExtensionRewrittenUrl = "Tap Safari Extension Rewritten URL" } + //TODO re-evaluate if these should go into the main analytic engine + enum Stat: String, AnalyticsStat { + case blockscanChatFetchUnread + } + //Include "Error" at the end of the String value so it's easier to filter in analytics dashboard enum Error: String, AnalyticsError { case sendTransactionNonceTooLow = "Send Transaction Nonce Too Low Error" @@ -204,4 +213,11 @@ enum Analytics { case cancelTransactionInsufficientFunds case walletTab } -} + + enum BlockscanChatResultType: String { + case nonZero + case zero + case error429 + case errorOthers + } +} \ No newline at end of file diff --git a/AlphaWallet/BlockscanChat/RemoteCounter.swift b/AlphaWallet/BlockscanChat/RemoteCounter.swift deleted file mode 100644 index 750fa7ce4..000000000 --- a/AlphaWallet/BlockscanChat/RemoteCounter.swift +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright © 2022 Stormbird PTE. LTD. - -import Foundation -import PromiseKit - -class RemoteCounter { - private let key: String - - init(key: String) { - self.key = key - } - - func log(statName: String, value: Int) { - let parameters: [String: Any] = [ - "email": key, - "stat": statName, - "value": String(value), - ] - Alamofire.request(Constants.statHatEndPoint, method: .post, parameters: parameters) - } -} \ No newline at end of file diff --git a/AlphaWallet/InCoordinator.swift b/AlphaWallet/InCoordinator.swift index b444536a9..8ff0b175e 100644 --- a/AlphaWallet/InCoordinator.swift +++ b/AlphaWallet/InCoordinator.swift @@ -248,7 +248,7 @@ class InCoordinator: NSObject, Coordinator { walletSessions[each] = session } - + sessionsSubject.send(walletSessions) } @@ -287,21 +287,20 @@ class InCoordinator: NSObject, Coordinator { guard Features.isBlockscanChatEnabled else { return } guard !Constants.Credentials.blockscanChatProxyKey.isEmpty else { return } if let blockscanChat = blockscanChat { - RemoteCounter(key: Constants.Credentials.statHatKey).log(statName: "blockscanChat.unread.call", value: 1) firstly { blockscanChat.fetchUnreadCount() }.done { [weak self] unreadCount in if unreadCount > 0 { - RemoteCounter(key: Constants.Credentials.statHatKey).log(statName: "blockscanChat.unread.nonZero", value: 1) + self?.analyticsCoordinator.log(stat: Analytics.Stat.blockscanChatFetchUnread, properties: [Analytics.Properties.resultType.rawValue: Analytics.BlockscanChatResultType.nonZero.rawValue]) } else { - RemoteCounter(key: Constants.Credentials.statHatKey).log(statName: "blockscanChat.unread.zero", value: 1) + self?.analyticsCoordinator.log(stat: Analytics.Stat.blockscanChatFetchUnread, properties: [Analytics.Properties.resultType.rawValue: Analytics.BlockscanChatResultType.zero.rawValue]) } self?.settingsCoordinator?.showBlockscanChatUnreadCount(unreadCount) }.catch { [weak self] error in if let error = error as? AFError, let code = error.responseCode, code == 429 { - RemoteCounter(key: Constants.Credentials.statHatKey).log(statName: "blockscanChat.error.429", value: 1) + self?.analyticsCoordinator.log(stat: Analytics.Stat.blockscanChatFetchUnread, properties: [Analytics.Properties.resultType.rawValue: Analytics.BlockscanChatResultType.error429.rawValue]) } else { - RemoteCounter(key: Constants.Credentials.statHatKey).log(statName: "blockscanChat.error.others", value: 1) + self?.analyticsCoordinator.log(stat: Analytics.Stat.blockscanChatFetchUnread, properties: [Analytics.Properties.resultType.rawValue: Analytics.BlockscanChatResultType.errorOthers.rawValue]) } self?.settingsCoordinator?.showBlockscanChatUnreadCount(nil) }