Skip to content

Commit b25168e

Browse files
authored
Shared: Add subscription subscribe AppsFlyer analytic event (#939)
^ALTAPPS-1164
1 parent 87556c0 commit b25168e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.hyperskill.app.paywall.domain.analytic
2+
3+
import org.hyperskill.app.analytic.domain.model.apps_flyer.AppsFlyerAnalyticEvent
4+
5+
/**
6+
* Represents an analytic event when user purchases a subscription.
7+
*/
8+
object PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent : AppsFlyerAnalyticEvent(name = "af_subscribe")

shared/src/commonMain/kotlin/org/hyperskill/app/paywall/presentation/PaywallReducer.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.hyperskill.app.paywall.domain.analytic.PaywallClickedBuySubscriptionH
66
import org.hyperskill.app.paywall.domain.analytic.PaywallClickedContinueWithLimitsHyperskillAnalyticEvent
77
import org.hyperskill.app.paywall.domain.analytic.PaywallClickedRetryContentLoadingHyperskillAnalyticEvent
88
import org.hyperskill.app.paywall.domain.analytic.PaywallClickedTermsOfServiceAndPrivacyPolicyHyperskillAnalyticEvent
9+
import org.hyperskill.app.paywall.domain.analytic.PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent
910
import org.hyperskill.app.paywall.domain.analytic.PaywallViewedHyperskillAnalyticEvent
1011
import org.hyperskill.app.paywall.domain.model.PaywallTransitionSource
1112
import org.hyperskill.app.paywall.presentation.PaywallFeature.Action
@@ -98,7 +99,12 @@ internal class PaywallReducer(
9899
): ReducerResult =
99100
if (state is State.Content) {
100101
when (message.purchaseResult) {
101-
is PurchaseResult.Succeed,
102+
is PurchaseResult.Succeed -> {
103+
state.copy(isPurchaseSyncLoadingShowed = true) to setOf(
104+
InternalAction.SyncSubscription,
105+
InternalAction.LogAnalyticEvent(PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent)
106+
)
107+
}
102108
is PurchaseResult.Error.ProductAlreadyPurchasedError -> {
103109
state.copy(isPurchaseSyncLoadingShowed = true) to
104110
setOf(InternalAction.SyncSubscription)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.hyperskill.paywall
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertTrue
5+
import org.hyperskill.ResourceProviderStub
6+
import org.hyperskill.app.paywall.domain.analytic.PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent
7+
import org.hyperskill.app.paywall.domain.model.PaywallTransitionSource
8+
import org.hyperskill.app.paywall.presentation.PaywallFeature
9+
import org.hyperskill.app.paywall.presentation.PaywallFeature.InternalAction
10+
import org.hyperskill.app.paywall.presentation.PaywallFeature.InternalMessage
11+
import org.hyperskill.app.paywall.presentation.PaywallReducer
12+
import org.hyperskill.app.purchases.domain.model.PurchaseResult
13+
14+
class PaywallTest {
15+
private val reducer = PaywallReducer(
16+
paywallTransitionSource = PaywallTransitionSource.LOGIN,
17+
resourceProvider = ResourceProviderStub()
18+
)
19+
20+
@Test
21+
fun `Success subscription purchase should log analytic event`() {
22+
val (_, actions) = reducer.reduce(
23+
PaywallFeature.State.Content(formattedPrice = "", isPurchaseSyncLoadingShowed = false),
24+
InternalMessage.MobileOnlySubscriptionPurchaseSuccess(
25+
PurchaseResult.Succeed(orderId = null, productIds = emptyList())
26+
)
27+
)
28+
assertTrue {
29+
actions.any {
30+
it == InternalAction.LogAnalyticEvent(PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent)
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)