diff --git a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt index 4998d03..266f087 100644 --- a/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt @@ -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 @@ -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 /** @@ -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? { + 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 } } } diff --git a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt index c72dd95..c28ee0f 100644 --- a/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/AppsflyerKitTests.kt @@ -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)) } } \ No newline at end of file