diff --git a/app/src/main/java/com/tangem/tap/common/analytics/handlers/customerio/CustomerIoAnalyticsHandler.kt b/app/src/main/java/com/tangem/tap/common/analytics/handlers/customerio/CustomerIoAnalyticsHandler.kt index 2c34c4518b..a86b651af3 100644 --- a/app/src/main/java/com/tangem/tap/common/analytics/handlers/customerio/CustomerIoAnalyticsHandler.kt +++ b/app/src/main/java/com/tangem/tap/common/analytics/handlers/customerio/CustomerIoAnalyticsHandler.kt @@ -33,13 +33,14 @@ class CustomerIoAnalyticsHandler( class Builder : AnalyticsHandlerBuilder { override fun build(data: AnalyticsHandlerBuilder.Data): AnalyticsHandler? { + val cdpApiKey = data.config.customerIoCdpApiKey return if (data.logConfig.isCustomerIoLogEnabled) { CustomerIoAnalyticsHandler(client = CustomerIoLogClient()) - } else if (data.config.customerIoCdpApiKey.isNotBlank()) { + } else if (!cdpApiKey.isNullOrBlank()) { CustomerIoAnalyticsHandler( client = CustomerIoClient( application = data.application, - cdpApiKey = data.config.customerIoCdpApiKey, + cdpApiKey = cdpApiKey, ), ) } else { diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/config/environment/EnvironmentConfig.kt b/core/datasource/src/main/java/com/tangem/datasource/local/config/environment/EnvironmentConfig.kt index b8624c9ec8..e513869876 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/config/environment/EnvironmentConfig.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/config/environment/EnvironmentConfig.kt @@ -28,5 +28,7 @@ data class EnvironmentConfig( val bffStaticTokenDev: String? = null, val gaslessTxApiKeyDev: String? = null, val gaslessTxApiKey: String? = null, - val customerIoCdpApiKey: String = "", + val customerIoCdpApiKey: String? = null, + val surveySparrowDomain: String? = null, + val surveySparrowToken: String? = null, ) \ No newline at end of file diff --git a/features/tester/impl/build.gradle.kts b/features/tester/impl/build.gradle.kts index 68cab10425..6554b8a54f 100644 --- a/features/tester/impl/build.gradle.kts +++ b/features/tester/impl/build.gradle.kts @@ -49,6 +49,7 @@ dependencies { implementation(deps.arrow.core) implementation(deps.kotlin.immutable.collections) implementation(deps.timber) + implementation(deps.surveysparrow) /** Core modules */ implementation(projects.core.datasource) diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt index a5dfc60808..f6467fef58 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt @@ -1,5 +1,6 @@ package com.tangem.feature.tester.presentation +import android.widget.Toast import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -17,6 +18,7 @@ import com.tangem.core.navigation.finisher.AppFinisher import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeActivity +import com.tangem.datasource.local.config.environment.EnvironmentConfig import com.tangem.feature.tester.presentation.accounts.ui.AccountsScreen import com.tangem.feature.tester.presentation.accounts.viewmodel.TesterAccountsViewModel import com.tangem.feature.tester.presentation.actions.TesterActionsScreen @@ -35,9 +37,10 @@ import com.tangem.feature.tester.presentation.menu.ui.TesterMenuScreen import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter import com.tangem.feature.tester.presentation.navigation.TesterScreen import com.tangem.feature.tester.presentation.providers.ui.BlockchainProvidersScreen +import com.tangem.feature.tester.presentation.providers.viewmodel.BlockchainProvidersViewModel import com.tangem.feature.tester.presentation.storybook.ui.StoryBookScreen import com.tangem.feature.tester.presentation.storybook.viewmodel.StoryBookViewModel -import com.tangem.feature.tester.presentation.providers.viewmodel.BlockchainProvidersViewModel +import com.tangem.feature.tester.presentation.surveysparrow.SurveySparrowManager import com.tangem.feature.tester.presentation.testpush.ui.TestPushScreen import com.tangem.feature.tester.presentation.testpush.viewmodel.TestPushViewModel import dagger.hilt.android.AndroidEntryPoint @@ -60,6 +63,9 @@ internal class TesterActivity : ComposeActivity() { @Inject lateinit var appRouter: AppRouter + @Inject + lateinit var environmentConfig: EnvironmentConfig + @Composable override fun ScreenContent(modifier: Modifier) { val systemBarsColor = TangemTheme.colors.background.secondary @@ -89,6 +95,7 @@ internal class TesterActivity : ComposeActivity() { ButtonUM.ACCOUNTS, ButtonUM.ADDRESSES_INFO, ButtonUM.STORY_BOOK, + ButtonUM.SURVEY_SPARROW, ), onButtonClick = { buttonUM -> val route = when (buttonUM) { @@ -101,6 +108,7 @@ internal class TesterActivity : ComposeActivity() { ButtonUM.ACCOUNTS -> TesterScreen.ACCOUNTS ButtonUM.ADDRESSES_INFO -> TesterScreen.ADDRESSES_INFO ButtonUM.STORY_BOOK -> TesterScreen.STORY_BOOK + ButtonUM.SURVEY_SPARROW -> TesterScreen.SURVEY_SPARROW } innerTesterRouter.open(route) @@ -192,6 +200,42 @@ internal class TesterActivity : ComposeActivity() { StoryBookScreen(state) } + + composable(route = TesterScreen.SURVEY_SPARROW.name) { + LaunchedEffect(Unit) { + val isSuccess = startSurveySparrow() + if (isSuccess) { + innerTesterRouter.back() + } + } + } } } + + private fun startSurveySparrow(): Boolean { + val domain = environmentConfig.surveySparrowDomain + val token = environmentConfig.surveySparrowToken + + if (domain.isNullOrEmpty() || token.isNullOrEmpty()) { + val toast = Toast.makeText( + this, + "Survey Sparrow is not configured. Domain or token is missing.", + Toast.LENGTH_LONG, + ) + + toast.show() + return false + } + + SurveySparrowManager(domain = domain, token = token).startSurveyForResult( + activity = this, + requestCode = SURVEY_SPARROW_REQUEST_CODE, + ) + + return true + } + + private companion object { + const val SURVEY_SPARROW_REQUEST_CODE = 1001 + } } \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/menu/state/TesterMenuUM.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/menu/state/TesterMenuUM.kt index e3318e0cab..59523e315d 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/menu/state/TesterMenuUM.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/menu/state/TesterMenuUM.kt @@ -27,5 +27,6 @@ data class TesterMenuUM( ACCOUNTS(R.string.accounts), ADDRESSES_INFO(R.string.addresses_info), STORY_BOOK(R.string.story_book), + SURVEY_SPARROW(R.string.survey_sparrow), } } \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/TesterScreen.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/TesterScreen.kt index ca2ae6a0e9..09864f11b0 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/TesterScreen.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/TesterScreen.kt @@ -16,4 +16,5 @@ internal enum class TesterScreen { ACCOUNTS, ADDRESSES_INFO, STORY_BOOK, + SURVEY_SPARROW, } \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/surveysparrow/SurveySparrowManager.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/surveysparrow/SurveySparrowManager.kt new file mode 100644 index 0000000000..5a91649f19 --- /dev/null +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/surveysparrow/SurveySparrowManager.kt @@ -0,0 +1,55 @@ +package com.tangem.feature.tester.presentation.surveysparrow + +import android.app.Activity +import com.surveysparrow.ss_android_sdk.SsSurvey +import com.surveysparrow.ss_android_sdk.SurveySparrow +import timber.log.Timber + +/** + * Manager for Survey Sparrow SDK. + * + * @param domain Survey Sparrow domain (e.g., "yourcompany") + * @param token Survey Sparrow SDK token + */ +class SurveySparrowManager( + private val domain: String, + private val token: String, +) { + + /** + * Create a SurveySparrow instance to start a survey. + * + * @param activity The activity context + * @param customVariables Optional custom variables to pass to the survey + * @return SurveySparrow instance ready to start + */ + fun createSurvey(activity: Activity, customVariables: Map? = null): SurveySparrow? { + return try { + val survey = SsSurvey(domain, token).apply { + customVariables?.forEach { (key, value) -> + addCustomParam(key, value) + } + } + + SurveySparrow(activity, survey) + } catch (e: Exception) { + Timber.e(e, "Failed to create SurveySparrow survey") + null + } + } + + /** + * Start a survey for result. + * + * @param activity The activity context + * @param requestCode The request code for onActivityResult + * @param customVariables Optional custom variables to pass to the survey + */ + fun startSurveyForResult(activity: Activity, requestCode: Int, customVariables: Map? = null) { + val surveySparrow = createSurvey(activity, customVariables) + if (surveySparrow != null) { + surveySparrow.startSurveyForResult(requestCode) + Timber.d("SurveySparrow survey started with requestCode: $requestCode") + } + } +} \ No newline at end of file diff --git a/features/tester/impl/src/main/res/values/strings.xml b/features/tester/impl/src/main/res/values/strings.xml index 19d8c518ee..f6d9e5cf50 100644 --- a/features/tester/impl/src/main/res/values/strings.xml +++ b/features/tester/impl/src/main/res/values/strings.xml @@ -23,4 +23,5 @@ News details (Bottom Sheet) Addresses info Story book + Survey Sparrow diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index 7169e359a2..759030eecc 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -104,6 +104,7 @@ sumsub = "1.38.0" haze = "1.7.1" kotlinpoet = "1.18.1" customerio = "4.6.3" +surveysparrow = "1.2.9" # endregion Other libraries # region Tools @@ -316,4 +317,5 @@ haze = { module = "dev.chrisbanes.haze:haze", version.ref = "haze" } haze-materials = { module = "dev.chrisbanes.haze:haze-materials", version.ref = "haze" } customerio-analytics = { module = "io.customer.android:datapipelines", version.ref = "customerio" } customerio-messaging = { module = "io.customer.android:messaging-push-fcm", version.ref = "customerio" } +surveysparrow = { module = "com.github.surveysparrow:surveysparrow-android-sdk", version.ref = "surveysparrow" } # endregion Other