Skip to content

Commit 1e33b0d

Browse files
authored
fix: Forward product attribute with purchase events when products not bundled (#184)
1 parent 114496d commit 1e33b0d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/main/kotlin/com/mparticle/kits/AppboyKit.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,33 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
636636
}
637637
}
638638

639+
product.couponCode?.let {
640+
purchaseProperties.addProperty(
641+
CommerceEventUtils.Constants.ATT_PRODUCT_COUPON_CODE,
642+
it
643+
)
644+
}
645+
product.brand?.let {
646+
purchaseProperties.addProperty(CommerceEventUtils.Constants.ATT_PRODUCT_BRAND, it)
647+
}
648+
product.category?.let {
649+
purchaseProperties.addProperty(CommerceEventUtils.Constants.ATT_PRODUCT_CATEGORY, it)
650+
}
651+
product.name.let {
652+
purchaseProperties.addProperty(CommerceEventUtils.Constants.ATT_PRODUCT_NAME, it)
653+
}
654+
product.variant?.let {
655+
purchaseProperties.addProperty(CommerceEventUtils.Constants.ATT_PRODUCT_VARIANT, it)
656+
}
657+
product.position?.let {
658+
purchaseProperties.addProperty(CommerceEventUtils.Constants.ATT_PRODUCT_POSITION, it)
659+
}
660+
product.customAttributes?.let {
661+
for ((key, value) in it) {
662+
purchaseProperties.addProperty(key, value)
663+
}
664+
}
665+
639666
var sanitizedProductName: String = product.sku
640667
try {
641668
if (settings[REPLACE_SKU_AS_PRODUCT_NAME] == "True") {

src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ class AppboyKitTests {
441441
val customAttributes = HashMap<String, String>()
442442
customAttributes["key1"] = "value1"
443443
customAttributes["key #2"] = "value #3"
444+
val productCustomAttributes = HashMap<String, String>()
445+
productCustomAttributes["productKey1"] = "value1"
446+
productCustomAttributes["productKey2"] = "value2"
444447
val transactionAttributes = TransactionAttributes("the id")
445448
.setTax(100.0)
446449
.setShipping(12.0)
@@ -449,6 +452,11 @@ class AppboyKitTests {
449452
.setAffiliation("the affiliation")
450453
val product = Product.Builder("product name", "sku1", 4.5)
451454
.quantity(5.0)
455+
.brand("testBrand")
456+
.variant("testVariant")
457+
.position(1)
458+
.category("testCategory")
459+
.customAttributes(productCustomAttributes)
452460
.build()
453461
val commerceEvent = CommerceEvent.Builder(Product.PURCHASE, product)
454462
.currency("Moon Dollars")
@@ -491,11 +499,35 @@ class AppboyKitTests {
491499
properties.remove(CommerceEventUtils.Constants.ATT_AFFILIATION),
492500
"the affiliation"
493501
)
502+
Assert.assertEquals(
503+
properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_NAME),
504+
"product name"
505+
)
506+
Assert.assertEquals(
507+
properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_CATEGORY),
508+
"testCategory"
509+
)
510+
Assert.assertEquals(
511+
properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_BRAND),
512+
"testBrand"
513+
)
514+
Assert.assertEquals(
515+
properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_POSITION),
516+
1
517+
)
518+
Assert.assertEquals(
519+
properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_VARIANT),
520+
"testVariant"
521+
)
494522

495523
//Custom Attributes
496524
Assert.assertEquals(properties.remove("key1"), "value1")
497525
Assert.assertEquals(properties.remove("key #2"), "value #3")
498526

527+
//Product Custom Attributes
528+
Assert.assertEquals(properties.remove("productKey1"), "value1")
529+
Assert.assertEquals(properties.remove("productKey2"), "value2")
530+
499531
val emptyAttributes = HashMap<String, String>()
500532
Assert.assertEquals(emptyAttributes, properties)
501533
}

0 commit comments

Comments
 (0)