Skip to content

Commit 4a268a6

Browse files
committed
parameters added for flutter and ios sdk differentiation
1 parent 7c961f9 commit 4a268a6

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

Sources/Web3Auth/Types.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ public struct AuthConnectionConfig: Codable {
163163
}
164164

165165
public struct Web3AuthOptions: Codable {
166+
167+
public var isFlutterAnalytics: Bool = false
168+
public var sdkVersion: String? = nil
169+
170+
public mutating func setFlutterAnalytics(_ isFlutter: Bool?, sdkVersion: String? = nil) {
171+
self.isFlutterAnalytics = isFlutter ?? false
172+
self.sdkVersion = sdkVersion
173+
}
174+
175+
public func getSdkName() -> String {
176+
return isFlutterAnalytics ? AnalyticsSdkType.flutter : AnalyticsSdkType.ios
177+
}
178+
179+
public func getSdkVersion() -> String {
180+
if let version = sdkVersion, !version.isEmpty {
181+
return version // Flutter SDK version
182+
}
183+
return AnalyticsEvents.iosSdkVersion // Default iOS SDK version
184+
}
185+
166186
public init(clientId: String, redirectUrl: String, originData: [String: String]? = nil, authBuildEnv: BuildEnv? = .production, sdkUrl: String? = nil,
167187
storageServerUrl: String? = nil,sessionSocketUrl: String? = nil, authConnectionConfig: [AuthConnectionConfig]? = nil,
168188
whiteLabel: WhiteLabelData? = nil, dashboardUrl: String? = nil, accountAbstractionConfig: String? = nil, walletSdkUrl: String? = nil,
@@ -248,7 +268,7 @@ public struct Web3AuthOptions: Codable {
248268
var web3AuthNetwork: Web3AuthNetwork
249269
var useSFAKey: Bool?
250270
var walletServicesConfig: WalletServicesConfig?
251-
let mfaSettings: MfaSettings?
271+
var mfaSettings: MfaSettings?
252272

253273

254274
enum CodingKeys: String, CodingKey {
@@ -732,6 +752,7 @@ public struct ProjectConfigResponse: Codable {
732752
public var walletConnectProjectId: String? = nil
733753
public var whitelabel: WhiteLabelData? = nil
734754
public var teamId: Int? = nil
755+
public var mfaSettings: MfaSettings?
735756

736757
enum CodingKeys: String, CodingKey {
737758
case userDataInIdToken
@@ -747,6 +768,7 @@ public struct ProjectConfigResponse: Codable {
747768
case walletConnectProjectId
748769
case whitelabel
749770
case teamId
771+
case mfaSettings
750772
}
751773

752774
public init(from decoder: Decoder) throws {
@@ -764,6 +786,7 @@ public struct ProjectConfigResponse: Codable {
764786
self.walletConnectProjectId = try container.decodeIfPresent(String.self, forKey: .walletConnectProjectId)
765787
self.whitelabel = try container.decodeIfPresent(WhiteLabelData.self, forKey: .whitelabel)
766788
self.teamId = try container.decodeIfPresent(Int.self, forKey: .teamId)
789+
self.mfaSettings = try container.decodeIfPresent(MfaSettings.self, forKey: .mfaSettings)
767790
}
768791
}
769792

@@ -813,3 +836,17 @@ public struct Web3AuthSubVerifierInfo: Codable {
813836
var idToken: String
814837
}
815838

839+
extension MfaSettings {
840+
func merge(with other: MfaSettings?) -> MfaSettings {
841+
guard let other = other else { return self }
842+
return MfaSettings(
843+
deviceShareFactor: other.deviceShareFactor ?? self.deviceShareFactor,
844+
backUpShareFactor: other.backUpShareFactor ?? self.backUpShareFactor,
845+
socialBackupFactor: other.socialBackupFactor ?? self.socialBackupFactor,
846+
passwordFactor: other.passwordFactor ?? self.passwordFactor,
847+
passkeysFactor: other.passkeysFactor ?? self.passkeysFactor,
848+
authenticatorFactor: other.authenticatorFactor ?? self.authenticatorFactor
849+
)
850+
}
851+
}
852+

Sources/Web3Auth/Web3Auth.swift

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public class Web3Auth: NSObject {
6969
)
7070

7171
AnalyticsManager.shared.setGlobalProperties([
72-
"sdk_name": AnalyticsSdkType.ios,
73-
"sdk_version": AnalyticsEvents.sdkVersion,
72+
"sdk_name": options.getSdkName(),
73+
"sdk_version": options.getSdkVersion(),
7474
"web3auth_client_id": options.clientId,
7575
"web3auth_network": options.web3AuthNetwork
7676
])
@@ -269,7 +269,7 @@ public class Web3Auth: NSObject {
269269
"chain_id": web3AuthOptions.defaultChainId?.description ?? "",
270270
"dapp_url": loginParams.dappUrl ?? "",
271271
"chains": web3AuthOptions.chains?.description ?? "[]",
272-
"integration_type": "ios",
272+
"integration_type": web3AuthOptions.getSdkName(),
273273
"is_sfa": false
274274
]
275275

@@ -499,7 +499,7 @@ public class Web3Auth: NSObject {
499499
"chain_id": web3AuthOptions.defaultChainId?.description ?? "",
500500
"dapp_url": loginParams.dappUrl ?? "",
501501
"chains": web3AuthOptions.chains?.description ?? "[]",
502-
"integration_type": "ios",
502+
"integration_type": web3AuthOptions.getSdkName(),
503503
"is_sfa": true
504504
]
505505

@@ -540,7 +540,7 @@ public class Web3Auth: NSObject {
540540
AnalyticsManager.shared.trackEvent(
541541
AnalyticsEvents.mfaEnablementStarted,
542542
properties: [
543-
"integration_type": AnalyticsSdkType.ios,
543+
"integration_type": web3AuthOptions.getSdkName(),
544544
"dapp_url": loginParams?.dappUrl ?? "",
545545
"connector": "auth",
546546
"duration": duration
@@ -576,7 +576,7 @@ public class Web3Auth: NSObject {
576576
let newSessionId = try SessionManager.generateRandomSessionID()!
577577
let loginIdObject: [String: String?] = [
578578
"loginId": newSessionId,
579-
"platform": "iOS",
579+
"platform": web3AuthOptions.getSdkName(),
580580
]
581581

582582
let jsonEncoder = JSONEncoder()
@@ -646,7 +646,7 @@ public class Web3Auth: NSObject {
646646
"chain_id": self.web3AuthOptions.defaultChainId?.description ?? "",
647647
"dapp_url": loginParams?.dappUrl ?? "",
648648
"chains": self.web3AuthOptions.chains?.description ?? "[]",
649-
"integration_type": "ios",
649+
"integration_type": self.web3AuthOptions.getSdkName(),
650650
"is_sfa": false
651651
]
652652

@@ -679,7 +679,7 @@ public class Web3Auth: NSObject {
679679
AnalyticsManager.shared.trackEvent(
680680
AnalyticsEvents.mfaManagementStarted,
681681
properties: [
682-
"integration_type": "ios",
682+
"integration_type": web3AuthOptions.getSdkName(),
683683
"dapp_url": loginParams?.dappUrl ?? "",
684684
"connector": "auth"
685685
]
@@ -764,7 +764,7 @@ public class Web3Auth: NSObject {
764764
"chain_id": self.web3AuthOptions.defaultChainId?.description ?? "",
765765
"dapp_url": loginParams?.dappUrl ?? "",
766766
"chains": self.web3AuthOptions.chains?.description ?? "[]",
767-
"integration_type": "ios",
767+
"integration_type": self.web3AuthOptions.getSdkName(),
768768
"is_sfa": false
769769
]
770770

@@ -800,7 +800,7 @@ public class Web3Auth: NSObject {
800800
AnalyticsManager.shared.trackEvent(
801801
AnalyticsEvents.walletUIClicked,
802802
properties: [
803-
"integration_type": AnalyticsSdkType.ios,
803+
"integration_type": web3AuthOptions.getSdkName(),
804804
"dapp_url": loginParams?.dappUrl ?? ""
805805
]
806806
)
@@ -868,7 +868,7 @@ public class Web3Auth: NSObject {
868868
AnalyticsManager.shared.trackEvent(
869869
AnalyticsEvents.walletServicesFailed,
870870
properties: [
871-
"integration_type": AnalyticsSdkType.ios,
871+
"integration_type": web3AuthOptions.getSdkName(),
872872
"dapp_url": loginParams?.dappUrl ?? "",
873873
"duration": Int(Date().timeIntervalSince1970 * 1000) - Int(startTime),
874874
"error": "Wallet Services Error: SessionId not found. Please login first."
@@ -1038,31 +1038,26 @@ public class Web3Auth: NSObject {
10381038
// os_log("fetchProjectConfig API response is: %@", log: getTorusLogger(log: Web3AuthLogger.network, type: .info), type: .info, "\(String(describing: result))")
10391039
projectConfigResponse = result
10401040
AnalyticsManager.shared.setGlobalProperties([
1041-
"sdk_name": AnalyticsSdkType.ios,
1042-
"sdk_version": AnalyticsEvents.sdkVersion,
1041+
"sdk_name": web3AuthOptions.getSdkName(),
1042+
"sdk_version": web3AuthOptions.getSdkVersion(),
10431043
"web3auth_client_id": web3AuthOptions.clientId,
10441044
"web3auth_network": web3AuthOptions.web3AuthNetwork,
10451045
"team_id" : projectConfigResponse?.teamId.toString()
10461046
])
10471047

10481048
let duration = Int(Date().timeIntervalSince1970 * 1000) - Int(startTime)
1049-
1049+
let chainIds: [String] = web3AuthOptions.chains?.compactMap { $0.chainId } ?? []
10501050
let properties: [String: Any] = [
1051-
"chain_ids": ["eip155", "solana", "other"],
1051+
"chain_ids" : chainIds,
1052+
"chain_nameSpaces": ["eip155", "solana", "other"],
10521053
"logging_enabled": web3AuthOptions.enableLogging,
10531054
"auth_build_env": web3AuthOptions.authBuildEnv?.rawValue,
1054-
"auth_ux_mode": "popup",
1055-
"auth_mfa_settings": [String](),
1055+
"auth_mfa_settings": web3AuthOptions.mfaSettings,
10561056
"whitelabel_logo_light_enabled": web3AuthOptions.whiteLabel?.logoLight != nil,
10571057
"whitelabel_logo_dark_enabled": web3AuthOptions.whiteLabel?.logoDark != nil,
10581058
"whitelabel_theme_mode": web3AuthOptions.whiteLabel?.theme as Any,
1059-
"ui_login_methods_order": [
1060-
"google", "twitter", "facebook", "discord", "farcaster", "apple",
1061-
"github", "reddit", "line", "kakao", "linkedin", "twitch",
1062-
"wechat", "email_passwordless", "sms_passwordless"
1063-
],
10641059
"duration": duration,
1065-
"integration_type": "ios",
1060+
"integration_type": web3AuthOptions.getSdkName(),
10661061
"dapp_url": self.loginParams?.dappUrl as Any
10671062
]
10681063

@@ -1074,6 +1069,8 @@ public class Web3Auth: NSObject {
10741069
web3AuthOptions.originData = result.whitelist.signedUrls.merging(web3AuthOptions.originData ?? [:]) { _, new in new }
10751070
web3AuthOptions.authConnectionConfig =
10761071
(web3AuthOptions.authConnectionConfig ?? []) + (projectConfigResponse?.embeddedWalletAuth ?? [])
1072+
web3AuthOptions.mfaSettings = web3AuthOptions.mfaSettings?.merge(with: projectConfigResponse?.mfaSettings)
1073+
?? projectConfigResponse?.mfaSettings
10771074
if let whiteLabelData = result.whitelabel {
10781075
web3AuthOptions.whiteLabel = web3AuthOptions.whiteLabel?.merge(with: whiteLabelData) ?? whiteLabelData
10791076
if web3AuthOptions.walletServicesConfig == nil {
@@ -1089,7 +1086,7 @@ public class Web3Auth: NSObject {
10891086
//print("Decoding failed: \(error)")
10901087
let duration = Int(Date().timeIntervalSince1970 * 1000) - Int(startTime)
10911088
let properties: [String: Any] = [
1092-
"integration_type": AnalyticsSdkType.ios,
1089+
"integration_type": web3AuthOptions.getSdkName(),
10931090
"dapp_url": self.loginParams?.dappUrl ?? "",
10941091
"duration": duration,
10951092
"error_message": error

Sources/Web3Auth/analytics/AnalyticsManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ enum AnalyticsEvents {
7676
static let requestFunctionCompleted = "Request Function Completed"
7777
static let requestFunctionFailed = "Request Function Failed"
7878

79-
static let sdkVersion = "12.0.0"
79+
static let iosSdkVersion = "12.0.0"
8080
}
8181

8282
enum AnalyticsSdkType {
8383
static let ios = "ios"
84+
static let flutter = "flutter"
8485
}
8586

0 commit comments

Comments
 (0)