From d003dcac693bd0bdd423240bf4bb56213d06e0e8 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 8 Aug 2025 10:43:19 +0400 Subject: [PATCH 1/5] feat: flag added to distinguish b/w flutter and android analytics. Signed-off-by: Gaurav Goel --- .../main/java/com/web3auth/core/Web3Auth.kt | 23 +++++++++---------- .../core/analytics/AnalyticsConstant.kt | 1 + .../web3auth/core/types/Web3AuthOptions.kt | 14 +++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 7e91441f..081810be 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,7 +86,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu ) AnalyticsManager.setGlobalProperties( mapOf( - "sdk_name" to AnalyticsSdkType.ANDROID, + "sdk_name" to web3AuthOptions.getSdkName(), "sdk_version" to AnalyticsEvents.SDK_VERSION, "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,7 +854,7 @@ 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_name" to web3AuthOption.getSdkName(), "sdk_version" to AnalyticsEvents.SDK_VERSION, "web3auth_client_id" to web3AuthOption.clientId, "web3auth_network" to web3AuthOption.web3AuthNetwork, @@ -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..df7d22d8 100644 --- a/core/src/main/java/com/web3auth/core/analytics/AnalyticsConstant.kt +++ b/core/src/main/java/com/web3auth/core/analytics/AnalyticsConstant.kt @@ -26,6 +26,7 @@ object AnalyticsEvents { 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..8b03fc58 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,7 @@ package com.web3auth.core.types import androidx.annotation.Keep import com.google.gson.annotations.SerializedName +import com.web3auth.core.analytics.AnalyticsSdkType import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork @Keep @@ -30,6 +31,19 @@ data class Web3AuthOptions( @Keep val walletServicesConfig: WalletServicesConfig? = null, @Keep var mfaSettings: MfaSettings? = null, ) { + + @Transient + private var isFlutterAnalytics: Boolean? = false + fun setIsFlutterAnalytics(analytics: Boolean?) { + this.isFlutterAnalytics = analytics ?: false + } + + fun isFlutterAnalytics(): Boolean? = isFlutterAnalytics + + fun getSdkName(): String { + return if (isFlutterAnalytics == true) AnalyticsSdkType.FLUTTER else AnalyticsSdkType.ANDROID + } + init { if (dashboardUrl == null) { dashboardUrl = getDashboardUrl(authBuildEnv) From d2d6d58aa9c5119f455f6e7d54dcf2aa4db82f00 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 8 Aug 2025 11:06:46 +0400 Subject: [PATCH 2/5] feat: flag added to distinguish b/w flutter and android analytics. Signed-off-by: Gaurav Goel --- .../main/java/com/web3auth/core/analytics/AnalyticsManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt b/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt index eba80edc..677f4be4 100644 --- a/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt +++ b/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt @@ -9,7 +9,7 @@ import com.web3auth.core.BuildConfig internal object AnalyticsManager { private const val SEGMENT_WRITE_KEY = - SegmentKeys.SEGMENT_WRITE_KEY // Use (SEGMENT_WRITE_KEY) in production builds and (SEGMENT_WRITE_KEY_DEV) in development/testing builds + SegmentKeys.SEGMENT_WRITE_KEY_DEV // Use (SEGMENT_WRITE_KEY) in production builds and (SEGMENT_WRITE_KEY_DEV) in development/testing builds private var analytics: Analytics? = null private var isInitialized = false From 7887b50905510ddbcd64ee9bd306df625d455d7b Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 8 Aug 2025 11:17:57 +0400 Subject: [PATCH 3/5] feat: add sdkVersion wrt to flutter and android Signed-off-by: Gaurav Goel --- core/src/main/java/com/web3auth/core/Web3Auth.kt | 4 ++-- .../web3auth/core/analytics/AnalyticsConstant.kt | 2 +- .../com/web3auth/core/types/Web3AuthOptions.kt | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/Web3Auth.kt b/core/src/main/java/com/web3auth/core/Web3Auth.kt index 081810be..70962212 100644 --- a/core/src/main/java/com/web3auth/core/Web3Auth.kt +++ b/core/src/main/java/com/web3auth/core/Web3Auth.kt @@ -87,7 +87,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.setGlobalProperties( mapOf( "sdk_name" to web3AuthOptions.getSdkName(), - "sdk_version" to AnalyticsEvents.SDK_VERSION, + "sdk_version" to web3AuthOptions.getSdkVersion(), "web3auth_client_id" to web3AuthOptions.clientId, "web3auth_network" to web3AuthOptions.web3AuthNetwork, ) @@ -855,7 +855,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu AnalyticsManager.setGlobalProperties( mapOf( "sdk_name" to web3AuthOption.getSdkName(), - "sdk_version" to AnalyticsEvents.SDK_VERSION, + "sdk_version" to web3AuthOption.getSdkVersion(), "web3auth_client_id" to web3AuthOption.clientId, "web3auth_network" to web3AuthOption.web3AuthNetwork, "team_id" to projectConfigResponse?.teamId.toString(), 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 df7d22d8..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,7 +21,7 @@ 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 { 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 8b03fc58..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,7 @@ 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 @@ -34,11 +35,20 @@ data class Web3AuthOptions( @Transient private var isFlutterAnalytics: Boolean? = false - fun setIsFlutterAnalytics(analytics: Boolean?) { + private var sdkVersion: String? = null + fun setFlutterAnalytics(analytics: Boolean?, sdkVersion: String? = null) { this.isFlutterAnalytics = analytics ?: false + this.sdkVersion = sdkVersion } - fun isFlutterAnalytics(): Boolean? = isFlutterAnalytics + 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 From 6794bf091aa3ba007119b90db9bf326c04dc7c53 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 8 Aug 2025 11:27:36 +0400 Subject: [PATCH 4/5] feat: comment isSkipped fuicntion for testing Signed-off-by: Gaurav Goel --- .../main/java/com/web3auth/core/analytics/AnalyticsManager.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt b/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt index 677f4be4..3502ff15 100644 --- a/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt +++ b/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt @@ -33,7 +33,7 @@ internal object AnalyticsManager { fun trackEvent(eventName: String, properties: Map? = null) { if (!isInitialized) return - if (isSkipped()) return + //if (isSkipped()) return val combinedProps = Properties().apply { globalProperties.forEach { (k, v) -> putValue(k, v) } @@ -45,7 +45,7 @@ internal object AnalyticsManager { fun identify(userId: String, traits: Map? = null) { if (!isInitialized) return - if (isSkipped()) return + //if (isSkipped()) return val traitsObj = traits?.let { Traits().apply { From 787bdffca0228441784467869288048038990182 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 8 Aug 2025 11:46:25 +0400 Subject: [PATCH 5/5] feat: revert analytics properties to prod version Signed-off-by: Gaurav Goel --- .../java/com/web3auth/core/analytics/AnalyticsManager.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt b/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt index 3502ff15..eba80edc 100644 --- a/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt +++ b/core/src/main/java/com/web3auth/core/analytics/AnalyticsManager.kt @@ -9,7 +9,7 @@ import com.web3auth.core.BuildConfig internal object AnalyticsManager { private const val SEGMENT_WRITE_KEY = - SegmentKeys.SEGMENT_WRITE_KEY_DEV // Use (SEGMENT_WRITE_KEY) in production builds and (SEGMENT_WRITE_KEY_DEV) in development/testing builds + SegmentKeys.SEGMENT_WRITE_KEY // Use (SEGMENT_WRITE_KEY) in production builds and (SEGMENT_WRITE_KEY_DEV) in development/testing builds private var analytics: Analytics? = null private var isInitialized = false @@ -33,7 +33,7 @@ internal object AnalyticsManager { fun trackEvent(eventName: String, properties: Map? = null) { if (!isInitialized) return - //if (isSkipped()) return + if (isSkipped()) return val combinedProps = Properties().apply { globalProperties.forEach { (k, v) -> putValue(k, v) } @@ -45,7 +45,7 @@ internal object AnalyticsManager { fun identify(userId: String, traits: Map? = null) { if (!isInitialized) return - //if (isSkipped()) return + if (isSkipped()) return val traitsObj = traits?.let { Traits().apply {