Replace StatHat logging for Blockscan Chat with Mixpanel

pull/4103/head
Hwee-Boon Yar 3 years ago
parent ef6cabcc78
commit bc67a46146
  1. 4
      AlphaWallet.xcodeproj/project.pbxproj
  2. 5
      AlphaWallet/Analytics/Coordinators/AnalyticsCoordinator.swift
  3. 5
      AlphaWallet/Analytics/Coordinators/AnalyticsService.swift
  4. 5
      AlphaWallet/Analytics/Coordinators/MixpanelCoordinator.swift
  5. 16
      AlphaWallet/Analytics/Models/AnalyticsTypes.swift
  6. 21
      AlphaWallet/BlockscanChat/RemoteCounter.swift
  7. 9
      AlphaWallet/InCoordinator.swift

@ -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 = "<group>"; };
5E7C7DC4B06C1A623788EEED /* WalletConnectSessionCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletConnectSessionCellViewModel.swift; sourceTree = "<group>"; };
5E7C7DCB0BDDD30D10130AE7 /* GetIsERC875Encode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetIsERC875Encode.swift; sourceTree = "<group>"; };
5E7C7DD30D23ACDDA7995355 /* RemoteCounter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteCounter.swift; sourceTree = "<group>"; };
5E7C7DD409C330DA4033F504 /* Keystore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Keystore.swift; sourceTree = "<group>"; };
5E7C7DD9C564F2C7DE435894 /* ConfirmSignMessageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfirmSignMessageTableViewCell.swift; sourceTree = "<group>"; };
5E7C7DDCCEDE8A14A9C49E4A /* TransactionRowViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionRowViewModel.swift; sourceTree = "<group>"; };
@ -3813,7 +3811,6 @@
isa = PBXGroup;
children = (
5E7C714BB4A095BE99B18F7A /* BlockscanChat.swift */,
5E7C7DD30D23ACDDA7995355 /* RemoteCounter.swift */,
);
path = BlockscanChat;
sourceTree = "<group>";
@ -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;
};

@ -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,6 +21,10 @@ 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)
}

@ -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)

@ -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)

@ -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
}
}

@ -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)
}
}

@ -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)
}

Loading…
Cancel
Save