diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 7e91441f..70962212 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -12,7 +12,6 @@ import com.google.gson.JsonArray import com.google.gson.JsonObject import com.web3auth.core.analytics.AnalyticsEvents import com.web3auth.core.analytics.AnalyticsManager -import com.web3auth.core.analytics.AnalyticsSdkType import com.web3auth.core.api.ApiHelper import com.web3auth.core.api.ApiService import com.web3auth.core.keystore.IS_SFA @@ -87,8 +86,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu ) AnalyticsManager.setGlobalProperties( mapOf( - "sdk_name" to AnalyticsSdkType.ANDROID, - "sdk_version" to AnalyticsEvents.SDK_VERSION, + "sdk_name" to web3AuthOptions.getSdkName(), + "sdk_version" to web3AuthOptions.getSdkVersion(), "web3auth_client_id" to web3AuthOptions.clientId, "web3auth_network" to web3AuthOptions.web3AuthNetwork, ) @@ -242,7 +241,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu "whitelabel_logo_dark_enabled" to (web3AuthOption.whiteLabel?.logoDark != null), "whitelabel_theme_mode" to (web3AuthOption.whiteLabel?.theme), "duration" to System.currentTimeMillis() - startTime, - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to this.loginParams?.dappUrl, ) @@ -269,7 +268,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.trackEvent( AnalyticsEvents.SDK_INITIALIZATION_FAILED, mutableMapOf( - "integration_type" to AnalyticsSdkType.ANDROID, + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to "this.loginParams?.dappUrl.toString()", "duration" to System.currentTimeMillis() - startTime, "error_message" to "Fetch project config API error. ${err.message}" @@ -321,7 +320,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.trackEvent( AnalyticsEvents.MFA_MANAGEMENT_FAILED, mutableMapOf( - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to this.loginParams?.dappUrl.toString(), "connector" to "auth", "duration" to System.currentTimeMillis() - startTime, @@ -588,7 +587,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu "dapp_url" to loginParams.dappUrl.toString(), "chain_id" to web3AuthOption.defaultChainId.toString(), "chains" to (web3AuthOption.chains?.toString() ?: "[]"), - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "is_mfa_enabled" to (actionType == "enable_mfa"), "is_sfa" to true ) @@ -743,7 +742,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.trackEvent( AnalyticsEvents.MFA_ENABLEMENT_STARTED, mutableMapOf( - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to this.loginParams?.dappUrl.toString(), "connector" to "auth", "duration" to System.currentTimeMillis() - startTime, @@ -769,7 +768,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.trackEvent( AnalyticsEvents.MFA_MANAGEMENT_STARTED, mutableMapOf( - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to this.loginParams?.dappUrl.toString(), "connector" to "auth" ) @@ -855,8 +854,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu // Set global properties for analytics after fetching project config AnalyticsManager.setGlobalProperties( mapOf( - "sdk_name" to AnalyticsSdkType.ANDROID, - "sdk_version" to AnalyticsEvents.SDK_VERSION, + "sdk_name" to web3AuthOption.getSdkName(), + "sdk_version" to web3AuthOption.getSdkVersion(), "web3auth_client_id" to web3AuthOption.clientId, "web3auth_network" to web3AuthOption.web3AuthNetwork, "team_id" to projectConfigResponse?.teamId.toString(), @@ -929,7 +928,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.trackEvent( AnalyticsEvents.WALLET_UI_CLICKED, mutableMapOf( - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to this.loginParams?.dappUrl.toString(), ) ) @@ -1003,7 +1002,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.trackEvent( AnalyticsEvents.WALLET_SERVICES_FAILED, mutableMapOf( - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "dapp_url" to this.loginParams?.dappUrl.toString(), "duration" to System.currentTimeMillis() - startTime, "error" to "Wallet Services Error: Session ID is not found. Please login first." @@ -1265,7 +1264,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu "dapp_url" to loginParams?.dappUrl.toString(), "chain_id" to web3AuthOption.defaultChainId.toString(), "chains" to (web3AuthOption.chains?.toString() ?: "[]"), - "integration_type" to "android", + "integration_type" to web3AuthOption.getSdkName(), "is_mfa_enabled" to (actionType == "enable_mfa"), "is_sfa" to false ) diff --git a/core/src/main/java/com/web3auth/core/analytics/AnalyticsConstant.kt b/core/src/main/java/com/web3auth/core/analytics/AnalyticsConstant.kt index 844dd854..23674d72 100644 --- a/core/src/main/java/com/web3auth/core/analytics/AnalyticsConstant.kt +++ b/core/src/main/java/com/web3auth/core/analytics/AnalyticsConstant.kt @@ -21,11 +21,12 @@ object AnalyticsEvents { const val REQUEST_FUNCTION_COMPLETED = "Request Function Completed" const val REQUEST_FUNCTION_FAILED = "Request Function Failed" - const val SDK_VERSION = "10.0.0" + const val ANDROID_SDK_VERSION = "10.0.0" } object AnalyticsSdkType { const val ANDROID = "android" + const val FLUTTER = "flutter" } object SegmentKeys { diff --git a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt index 2a5e4bec..74aa2116 100644 --- a/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt +++ b/core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt @@ -2,6 +2,8 @@ package com.web3auth.core.types import androidx.annotation.Keep import com.google.gson.annotations.SerializedName +import com.web3auth.core.analytics.AnalyticsEvents +import com.web3auth.core.analytics.AnalyticsSdkType import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork @Keep @@ -30,6 +32,28 @@ data class Web3AuthOptions( @Keep val walletServicesConfig: WalletServicesConfig? = null, @Keep var mfaSettings: MfaSettings? = null, ) { + + @Transient + private var isFlutterAnalytics: Boolean? = false + private var sdkVersion: String? = null + fun setFlutterAnalytics(analytics: Boolean?, sdkVersion: String? = null) { + this.isFlutterAnalytics = analytics ?: false + this.sdkVersion = sdkVersion + } + + fun getFlutterAnalytics(): Boolean? = isFlutterAnalytics + fun getSdkVersion(): String { + return if (sdkVersion.isNullOrEmpty()) { + AnalyticsEvents.ANDROID_SDK_VERSION // android sdk version + } else { + sdkVersion ?: "unknown" // flutter sdk version + } + } + + fun getSdkName(): String { + return if (isFlutterAnalytics == true) AnalyticsSdkType.FLUTTER else AnalyticsSdkType.ANDROID + } + init { if (dashboardUrl == null) { dashboardUrl = getDashboardUrl(authBuildEnv)