diff --git a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt index cff2fe1375..ff196b2f0e 100644 --- a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt +++ b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt @@ -1,5 +1,8 @@ package com.tangem.core.analytics.models +import com.tangem.core.analytics.models.AnalyticsParam.Key.REFERRAL +import com.tangem.core.analytics.models.AnalyticsParam.Key.REFERRAL_ID + sealed class AnalyticsParam { sealed class CardBalanceState(val value: String) { @@ -268,5 +271,12 @@ sealed class AnalyticsParam { const val ENS = "ENS" const val ENS_ADDRESS = "ENS Address" const val ACCOUNT_DERIVATION_FROM = "Account Derivation (from)" + const val REFERRAL = "Referral" + const val REFERRAL_ID = "Referral_ID" } -} \ No newline at end of file +} + +fun getReferralParams(referralId: String?): List> = listOf( + REFERRAL to (!referralId.isNullOrBlank()).toString().replaceFirstChar(Char::titlecase), + REFERRAL_ID to (referralId ?: "None"), +) \ No newline at end of file diff --git a/features/swap/impl/build.gradle.kts b/features/swap/impl/build.gradle.kts index 9be6f2453e..69dd4663a7 100644 --- a/features/swap/impl/build.gradle.kts +++ b/features/swap/impl/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { implementation(projects.core.analytics) implementation(projects.core.analytics.models) implementation(projects.core.configToggles) + implementation(projects.core.datasource) implementation(projects.core.navigation) implementation(projects.core.utils) implementation(projects.core.ui) diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt index fe69da29ce..b091a1fbfd 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt @@ -8,6 +8,7 @@ import com.tangem.core.analytics.models.AnalyticsParam.Key.PROVIDER import com.tangem.core.analytics.models.AnalyticsParam.Key.RECEIVE_TOKEN import com.tangem.core.analytics.models.AnalyticsParam.Key.SEND_TOKEN import com.tangem.core.analytics.models.AppsFlyerIncludedEvent +import com.tangem.core.analytics.models.getReferralParams import com.tangem.feature.swap.domain.models.domain.SwapProvider import com.tangem.feature.swap.domain.models.ui.FeeType @@ -86,6 +87,7 @@ sealed class SwapEvents( val receiveToken: String, val fromDerivationIndex: Int?, val toDerivationIndex: Int?, + val referralId: String?, ) : SwapEvents( event = "Swap in Progress Screen Opened", params = mapOf( @@ -96,6 +98,7 @@ sealed class SwapEvents( "Send Blockchain" to sendBlockchain, "Receive Blockchain" to receiveBlockchain, "Account Derivation From or To (optional)" to "$fromDerivationIndex, $toDerivationIndex", + *getReferralParams(referralId).toTypedArray(), ), ), AppsFlyerIncludedEvent diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt index 65dba91ee9..96763be19f 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt @@ -20,6 +20,7 @@ import com.tangem.core.navigation.url.UrlOpener import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.utils.InputNumberFormatter +import com.tangem.datasource.local.appsflyer.AppsFlyerStore import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles import com.tangem.domain.account.status.model.AccountCryptoCurrencyStatus import com.tangem.domain.account.status.usecase.GetAccountCurrencyStatusUseCase @@ -118,6 +119,7 @@ internal class SwapModel @Inject constructor( private val accountsFeatureToggles: AccountsFeatureToggles, private val getTangemPayCurrencyStatusUseCase: GetTangemPayCurrencyStatusUseCase, private val tangemPayWithdrawUseCase: TangemPayWithdrawUseCase, + private val appsFlyerStore: AppsFlyerStore, ) : Model() { private val params = paramsContainer.require() @@ -888,7 +890,7 @@ internal class SwapModel @Inject constructor( } } - private fun sendSuccessEvent() { + private suspend fun sendSuccessEvent() { val provider = dataState.selectedProvider ?: return val fee = dataState.selectedFee?.feeType ?: return val fromCurrency = dataState.fromCryptoCurrency?.currency ?: return @@ -906,6 +908,7 @@ internal class SwapModel @Inject constructor( receiveToken = toCurrency.symbol, fromDerivationIndex = fromDerivationIndex, toDerivationIndex = toDerivationIndex, + referralId = appsFlyerStore.get()?.refcode, ), ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt index dc160b2505..eedc7314e9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt @@ -10,6 +10,7 @@ import com.tangem.core.analytics.models.event.MainScreenAnalyticsEvent import com.tangem.core.analytics.utils.TrackingContextProxy import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model +import com.tangem.datasource.local.appsflyer.AppsFlyerStore import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles import com.tangem.domain.account.supplier.SingleAccountListSupplier import com.tangem.domain.account.usecase.IsAccountsModeEnabledUseCase @@ -105,6 +106,7 @@ internal class WalletModel @Inject constructor( private val isAccountsModeEnabledUseCase: IsAccountsModeEnabledUseCase, private val feedFeatureToggle: FeedFeatureToggle, private val bindRefcodeWithWalletUseCase: BindRefcodeWithWalletUseCase, + private val appsFlyerStore: AppsFlyerStore, val screenLifecycleProvider: ScreenLifecycleProvider, val innerWalletRouter: InnerWalletRouter, ) : Model() { @@ -235,6 +237,7 @@ internal class WalletModel @Inject constructor( accountsCount = accountsCount, theme = theme.value, isImported = selectedWallet.isImported(), + referralId = appsFlyerStore.get()?.refcode, ), ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt index e766bf4333..f92476350d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt @@ -1,9 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.analytics -import com.tangem.core.analytics.models.AnalyticsEvent -import com.tangem.core.analytics.models.AnalyticsParam -import com.tangem.core.analytics.models.AppsFlyerIncludedEvent -import com.tangem.core.analytics.models.OneTimeAnalyticsEvent +import com.tangem.core.analytics.models.* import com.tangem.domain.models.wallet.UserWalletId sealed class WalletScreenAnalyticsEvent { @@ -59,6 +56,7 @@ sealed class WalletScreenAnalyticsEvent { private val accountsCount: Int?, val theme: String, val isImported: Boolean, + val referralId: String?, ) : MainScreen( event = "Screen opened", params = buildMap { @@ -71,6 +69,7 @@ sealed class WalletScreenAnalyticsEvent { "Seedless" } put("Wallet Type", seedPhrase) + putAll(getReferralParams(referralId)) }, ), AppsFlyerIncludedEvent diff --git a/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt b/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt index 02f6ba56aa..629181b412 100644 --- a/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt +++ b/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/analytics/YieldSupplyAnalytics.kt @@ -6,6 +6,7 @@ import com.tangem.core.analytics.models.AnalyticsParam.Key.BLOCKCHAIN import com.tangem.core.analytics.models.AnalyticsParam.Key.ERROR_DESCRIPTION import com.tangem.core.analytics.models.AnalyticsParam.Key.TOKEN_PARAM import com.tangem.core.analytics.models.AppsFlyerIncludedEvent +import com.tangem.core.analytics.models.getReferralParams sealed class YieldSupplyAnalytics( event: String, @@ -103,22 +104,26 @@ sealed class YieldSupplyAnalytics( data class FundsEarned( val token: String, val blockchain: String, + val referralId: String?, ) : YieldSupplyAnalytics( event = "Funds Earned", params = mapOf( TOKEN_PARAM to token, BLOCKCHAIN to blockchain, + *getReferralParams(referralId).toTypedArray(), ), ), AppsFlyerIncludedEvent data class FundsWithdrawn( val token: String, val blockchain: String, + val referralId: String?, ) : YieldSupplyAnalytics( event = "Funds Withdrawn", params = mapOf( TOKEN_PARAM to token, BLOCKCHAIN to blockchain, + *getReferralParams(referralId).toTypedArray(), ), ), AppsFlyerIncludedEvent diff --git a/features/yield-supply/impl/build.gradle.kts b/features/yield-supply/impl/build.gradle.kts index e79c976bd4..f1b9082389 100644 --- a/features/yield-supply/impl/build.gradle.kts +++ b/features/yield-supply/impl/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { /** Core */ implementation(projects.core.configToggles) + implementation(projects.core.datasource) implementation(projects.core.decompose) implementation(projects.core.ui) implementation(projects.core.navigation) diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt index 6a2d3d2597..52fe5d3df6 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningModel.kt @@ -11,6 +11,7 @@ import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList +import com.tangem.datasource.local.appsflyer.AppsFlyerStore import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus @@ -65,6 +66,7 @@ internal class YieldSupplyStartEarningModel @Inject constructor( private val yieldSupplyGetMaxFeeUseCase: YieldSupplyGetMaxFeeUseCase, private val yieldSupplyGetCurrentFeeUseCase: YieldSupplyGetCurrentFeeUseCase, private val yieldSupplyRepository: YieldSupplyRepository, + private val appsFlyerStore: AppsFlyerStore, ) : Model(), YieldSupplyNotificationsComponent.ModelCallback { private val params: YieldSupplyStartEarningComponent.Params = paramsContainer.require() @@ -267,6 +269,7 @@ internal class YieldSupplyStartEarningModel @Inject constructor( YieldSupplyAnalytics.FundsEarned( blockchain = cryptoCurrency.network.name, token = cryptoCurrency.symbol, + referralId = appsFlyerStore.get()?.refcode, ), ) yieldSupplyFeeUM.transactionDataList.forEach { diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt index f327d6c82a..0a54db1fee 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt @@ -11,6 +11,7 @@ import com.tangem.core.navigation.url.UrlOpener import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList +import com.tangem.datasource.local.appsflyer.AppsFlyerStore import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.models.currency.CryptoCurrency @@ -61,6 +62,7 @@ internal class YieldSupplyStopEarningModel @Inject constructor( private val yieldSupplyAlertFactory: YieldSupplyAlertFactory, private val yieldSupplyDeactivateUseCase: YieldSupplyDeactivateUseCase, private val yieldSupplyRepository: YieldSupplyRepository, + private val appsFlyerStore: AppsFlyerStore, ) : Model(), YieldSupplyNotificationsComponent.ModelCallback { private val params: YieldSupplyStopEarningComponent.Params = paramsContainer.require() @@ -160,7 +162,7 @@ internal class YieldSupplyStopEarningModel @Inject constructor( yieldSupplyAlertFactory.onFailedTxEmailClick( userWallet = params.userWallet, cryptoCurrency = cryptoCurrency, - errorMessage = error.toString(), + errorMessage = errorMessage, ) } }, @@ -184,6 +186,7 @@ internal class YieldSupplyStopEarningModel @Inject constructor( YieldSupplyAnalytics.FundsWithdrawn( token = cryptoCurrency.symbol, blockchain = cryptoCurrency.network.name, + referralId = appsFlyerStore.get()?.refcode, ), ) val event = AnalyticsParam.TxSentFrom.Earning(