Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ import android.content.Context
import android.content.Intent
import android.location.Location
import android.os.Bundle
import com.appsflyer.AFInAppEventParameterName.*
import com.appsflyer.AFInAppEventParameterName.CONTENT_ID
import com.appsflyer.AFInAppEventParameterName.CONTENT_TYPE
import com.appsflyer.AFInAppEventParameterName.CURRENCY
import com.appsflyer.AFInAppEventParameterName.PRICE
import com.appsflyer.AFInAppEventParameterName.QUANTITY
import com.appsflyer.AFInAppEventParameterName.REVENUE
import com.appsflyer.AFInAppEventType
import com.appsflyer.AFInAppEventType.*
import com.appsflyer.AFInAppEventType.ADD_TO_CART
import com.appsflyer.AFInAppEventType.ADD_TO_WISH_LIST
import com.appsflyer.AFInAppEventType.INITIATED_CHECKOUT
import com.appsflyer.AFInAppEventType.PURCHASE
import com.appsflyer.AppsFlyerConversionListener
import com.appsflyer.AppsFlyerLib
import com.appsflyer.AppsFlyerProperties
Expand All @@ -24,7 +32,7 @@ import com.mparticle.internal.MPUtility
import org.json.JSONException
import org.json.JSONObject
import java.math.BigDecimal
import java.util.*
import java.util.LinkedList


/**
Expand Down Expand Up @@ -374,24 +382,12 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
const val APP_OPEN_ATTRIBUTION_RESULT =
"MPARTICLE_APPSFLYER_APP_OPEN_ATTRIBUTION_RESULT"

fun generateProductIdList(event: CommerceEvent?): String? {
if (event == null || event.products == null || event.products?.size == 0) {
return null
fun generateProductIdList(event: CommerceEvent?): List<String>? {
return event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let {
if (it.isNotEmpty()) {
it.map { it.sku.replace(COMMA, "%2C") }
} else { null }
}

val productIdList = StringBuilder()
event.products?.let {
for (product in it) {
val sku = product.sku
if (!KitUtils.isEmpty(sku)) {
productIdList.append(sku.replace(COMMA, "%2C"))
productIdList.append(COMMA)
}
}
}
return if (productIdList.isNotEmpty()) {
productIdList.substring(0, productIdList.length - 1)
} else null
}
}
}
7 changes: 4 additions & 3 deletions src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ class AppsflyerKitTests {
val event = CommerceEvent.Builder(Product.PURCHASE, product)
.transactionAttributes(TransactionAttributes("foo"))
.build()
assertEquals("foo-sku", AppsFlyerKit.generateProductIdList(event))
assertEquals(mutableListOf("foo-sku"), AppsFlyerKit.generateProductIdList(event))
val product2 = Product.Builder("foo-name-2", "foo-sku-2", 50.0).build()
val event2 = CommerceEvent.Builder(Product.PURCHASE, product)
.addProduct(product2)
.transactionAttributes(TransactionAttributes("foo"))
.build()
assertEquals("foo-sku,foo-sku-2", AppsFlyerKit.generateProductIdList(event2))
assertEquals(
mutableListOf("foo-sku","foo-sku-2"), AppsFlyerKit.generateProductIdList(event2))
val product3 = Product.Builder("foo-name-3", "foo-sku-,3", 50.0).build()
val event3 = CommerceEvent.Builder(Product.PURCHASE, product)
.addProduct(product2)
.addProduct(product3)
.transactionAttributes(TransactionAttributes("foo"))
.build()
assertEquals("foo-sku,foo-sku-2,foo-sku-%2C3", AppsFlyerKit.generateProductIdList(event3))
assertEquals(mutableListOf("foo-sku","foo-sku-2","foo-sku-%2C3"), AppsFlyerKit.generateProductIdList(event3))
}
}