Skip to content

Commit

Permalink
Add url parameter for passing the appSwitchUrl for Venmo analytic events
Browse files Browse the repository at this point in the history
  • Loading branch information
tdchow committed Nov 19, 2024
1 parent 8197283 commit 3a5017a
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class AnalyticsClient internal constructor(
endTime = analyticsEventParams.endTime,
endpoint = analyticsEventParams.endpoint,
experiment = analyticsEventParams.experiment,
paymentMethodsDisplayed = analyticsEventParams.paymentMethodsDisplayed
paymentMethodsDisplayed = analyticsEventParams.paymentMethodsDisplayed,
appSwitchUrl = analyticsEventParams.appSwitchUrl
)
configurationLoader.loadConfiguration { result ->
if (result is ConfigurationLoaderResult.Success) {
Expand Down Expand Up @@ -240,6 +241,7 @@ class AnalyticsClient internal constructor(
.putOpt(FPTI_KEY_MERCHANT_EXPERIMENT, event.experiment)
.putOpt(FPTI_KEY_MERCHANT_PAYMENT_METHODS_DISPLAYED,
event.paymentMethodsDisplayed.ifEmpty { null })
.putOpt(FPTI_KEY_URL, event.appSwitchUrl)
return json.toString()
}

Expand Down Expand Up @@ -292,6 +294,7 @@ class AnalyticsClient internal constructor(
private const val FPTI_KEY_ENDPOINT = "endpoint"
private const val FPTI_KEY_MERCHANT_EXPERIMENT = "experiment"
private const val FPTI_KEY_MERCHANT_PAYMENT_METHODS_DISPLAYED = "payment_methods_displayed"
private const val FPTI_KEY_URL = "url"

private const val FPTI_BATCH_KEY_VENMO_INSTALLED = "venmo_installed"
private const val FPTI_BATCH_KEY_PAYPAL_INSTALLED = "paypal_installed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal data class AnalyticsEvent(
val endTime: Long? = null,
val endpoint: String? = null,
val experiment: String? = null,
val paymentMethodsDisplayed: List<String> = emptyList()
val paymentMethodsDisplayed: List<String> = emptyList(),
val appSwitchUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ data class AnalyticsEventParams @JvmOverloads constructor(
var endTime: Long? = null,
var endpoint: String? = null,
val experiment: String? = null,
val paymentMethodsDisplayed: List<String> = emptyList()
val paymentMethodsDisplayed: List<String> = emptyList(),
val appSwitchUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AnalyticsClientUnitTest {
private lateinit var sut: AnalyticsClient

private var timestamp: Long = 0
private val returnUrlScheme = "com.braintreepayments.demo.braintree"

@Before
@Throws(InvalidArgumentException::class, GeneralSecurityException::class, IOException::class)
Expand Down Expand Up @@ -74,6 +75,7 @@ class AnalyticsClientUnitTest {
every { time.currentTime } returns 123
every { merchantRepository.authorization } returns authorization
every { merchantRepository.applicationContext } returns context
every { merchantRepository.returnUrlScheme } returns returnUrlScheme

configurationLoader = MockkConfigurationLoaderBuilder()
.configuration(configuration)
Expand Down Expand Up @@ -103,7 +105,7 @@ class AnalyticsClientUnitTest {
)
} returns mockk()

sut.sendEvent(eventName)
sut.sendEvent(eventName, AnalyticsEventParams(appSwitchUrl = returnUrlScheme))

val workSpec = workRequestSlot.captured.workSpec
assertEquals(AnalyticsWriteToDbWorker::class.java.name, workSpec.workerClassName)
Expand All @@ -115,7 +117,8 @@ class AnalyticsClientUnitTest {
"event_name": "sample-event-name",
"t": 123,
"is_vault": false,
"tenant_name": "Braintree"
"tenant_name": "Braintree",
"url": "$returnUrlScheme"
}
"""
val actualJSON = workSpec.input.getString(WORK_INPUT_KEY_ANALYTICS_JSON)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class VenmoClient internal constructor(

private val analyticsParams: AnalyticsEventParams
get() {
val eventParameters = AnalyticsEventParams()
val eventParameters = AnalyticsEventParams(appSwitchUrl = merchantRepository.returnUrlScheme)
eventParameters.payPalContextId = payPalContextId
eventParameters.linkType = LINK_TYPE
eventParameters.isVaultRequest = isVaultRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import com.braintreepayments.api.BrowserSwitchException
import com.braintreepayments.api.BrowserSwitchFinalResult
import com.braintreepayments.api.BrowserSwitchStartResult
import com.braintreepayments.api.core.AnalyticsClient
import com.braintreepayments.api.core.AnalyticsEventParams
import com.braintreepayments.api.core.BraintreeException
import com.braintreepayments.api.core.MerchantRepository

/**
* Responsible for launching the Venmo app to authenticate users
*/
class VenmoLauncher internal constructor(
private val browserSwitchClient: BrowserSwitchClient,
lazyAnalyticsClient: Lazy<AnalyticsClient>
private val merchantRepository: MerchantRepository,
lazyAnalyticsClient: Lazy<AnalyticsClient>,
) {

constructor() : this(
browserSwitchClient = BrowserSwitchClient(),
merchantRepository = MerchantRepository.instance,
lazyAnalyticsClient = AnalyticsClient.lazyInstance
)

Expand All @@ -40,7 +44,10 @@ class VenmoLauncher internal constructor(
activity: ComponentActivity,
paymentAuthRequest: VenmoPaymentAuthRequest.ReadyToLaunch
): VenmoPendingRequest {
analyticsClient.sendEvent(VenmoAnalytics.APP_SWITCH_STARTED)
analyticsClient.sendEvent(
eventName = VenmoAnalytics.APP_SWITCH_STARTED,
analyticsEventParams = analyticsEventParams
)
try {
assertCanPerformBrowserSwitch(activity, paymentAuthRequest.requestParams)
} catch (browserSwitchException: BrowserSwitchException) {
Expand Down Expand Up @@ -80,7 +87,10 @@ class VenmoLauncher internal constructor(
pendingRequest: VenmoPendingRequest.Started,
intent: Intent
): VenmoPaymentAuthResult {
analyticsClient.sendEvent(VenmoAnalytics.HANDLE_RETURN_STARTED)
analyticsClient.sendEvent(
eventName = VenmoAnalytics.HANDLE_RETURN_STARTED,
analyticsEventParams = analyticsEventParams
)
return when (val browserSwitchResult =
browserSwitchClient.completeRequest(intent, pendingRequest.pendingRequestString)) {
is BrowserSwitchFinalResult.Success -> VenmoPaymentAuthResult.Success(
Expand Down Expand Up @@ -114,6 +124,8 @@ class VenmoLauncher internal constructor(
browserSwitchClient.assertCanPerformBrowserSwitch(activity, params.browserSwitchOptions)
}

private val analyticsEventParams by lazy { AnalyticsEventParams(appSwitchUrl = merchantRepository.returnUrlScheme) }

companion object {
private const val VENMO_PACKAGE_NAME = "com.venmo"
private fun createBrowserSwitchError(exception: BrowserSwitchException): Exception {
Expand Down
Loading

0 comments on commit 3a5017a

Please sign in to comment.