-
Notifications
You must be signed in to change notification settings - Fork 13
fix: Add enum value to hash ecommerce event attributes #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from 2 commits
44965b6
edf1408
f932c03
50902e2
fd439ba
c162935
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,19 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, | |
| ): List<ReportingMessage> = emptyList() | ||
|
|
||
| override fun logEvent(event: MPEvent): List<ReportingMessage> { | ||
| if (event.customAttributes != null) { | ||
| event.customAttributeStrings?.let { | ||
| changeUserArray( | ||
| it, | ||
| event.eventType.value, | ||
| event.eventName, false | ||
| ) | ||
| } | ||
| } | ||
| return logBrazeEvent(event) | ||
| } | ||
|
|
||
| private fun logBrazeEvent(event: MPEvent): List<ReportingMessage> { | ||
| val newAttributes: MutableMap<String, Any?> = HashMap() | ||
| if (event.customAttributes == null) { | ||
| Braze.getInstance(context).logCustomEvent(event.eventName) | ||
|
|
@@ -142,40 +155,55 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, | |
| val brazePropertiesSetter = BrazePropertiesSetter(properties, enableTypeDetection) | ||
| event.customAttributeStrings?.let { it -> | ||
| for ((key, value) in it) { | ||
| newAttributes[key] = brazePropertiesSetter.parseValue(key, value) | ||
| try { | ||
| newAttributes[key] = brazePropertiesSetter.parseValue(key, value) | ||
| } catch (e: Exception) { | ||
| Logger.warning("Exception while parsing custom attributes $e") | ||
| } | ||
| } | ||
| } | ||
| Braze.getInstance(context).logCustomEvent(event.eventName, properties) | ||
| Braze.getInstance(context).getCurrentUser(object : IValueCallback<BrazeUser> { | ||
| override fun onSuccess(value: BrazeUser) { | ||
| val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) | ||
| event.customAttributeStrings?.let { it -> | ||
| for ((key, attributeValue) in it) { | ||
| val hashedKey = | ||
| KitUtils.hashForFiltering(event.eventType.value.toString() + event.eventName + key) | ||
|
|
||
| configuration.eventAttributesAddToUser?.get(hashedKey)?.let { | ||
| value.addToCustomAttributeArray(it, attributeValue) | ||
| } | ||
| configuration.eventAttributesRemoveFromUser?.get(hashedKey)?.let { | ||
| value.removeFromCustomAttributeArray(it, attributeValue) | ||
| } | ||
| configuration.eventAttributesSingleItemUser?.get(hashedKey)?.let { | ||
| userAttributeSetter.parseValue(it, attributeValue) | ||
| } | ||
| queueDataFlush() | ||
| return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) | ||
| } | ||
|
|
||
| private fun changeUserArray( | ||
| customAttributes: Map<String, String>, | ||
| eventType: Int, | ||
| eventName: String?, | ||
| isCommerceEvent: Boolean | ||
| ) { | ||
| Braze.getInstance(context).getCurrentUser(object : IValueCallback<BrazeUser> { | ||
| override fun onSuccess(value: BrazeUser) { | ||
| val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) | ||
| customAttributes?.let { it -> | ||
| for ((key, attributeValue) in it) { | ||
| //for commerce event, event name is not required for generate hash | ||
| val hashedKey = | ||
| if (isCommerceEvent) { | ||
| KitUtils.hashForFiltering(eventType.toString() + key) | ||
| } else { | ||
| KitUtils.hashForFiltering(eventType.toString() + eventName + key) | ||
| } | ||
| configuration.eventAttributesAddToUser?.get(hashedKey)?.let { | ||
| value.addToCustomAttributeArray(it, attributeValue) | ||
| } | ||
| configuration.eventAttributesRemoveFromUser?.get(hashedKey)?.let { | ||
| value.removeFromCustomAttributeArray(it, attributeValue) | ||
| } | ||
| configuration.eventAttributesSingleItemUser?.get(hashedKey)?.let { | ||
| userAttributeSetter.parseValue(it, attributeValue) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun onError() { | ||
| Logger.warning("unable to acquire user to add or remove custom user attributes from events") | ||
| } | ||
| }) | ||
| } | ||
| queueDataFlush() | ||
| return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) | ||
| override fun onError() { | ||
| Logger.warning("unable to acquire user to add or remove custom user attributes from events") | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| override fun logScreen( | ||
| screenName: String, | ||
| screenAttributes: Map<String, String>? | ||
|
|
@@ -216,6 +244,10 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, | |
|
|
||
| override fun logEvent(event: CommerceEvent): List<ReportingMessage> { | ||
| val messages: MutableList<ReportingMessage> = LinkedList() | ||
| //For CommerceEvent, Event Name is not required to generate hash. So, it will be always null. | ||
| event.products?.get(0)?.customAttributes?.let { | ||
|
||
| changeUserArray(it, CommerceEventUtils.getEventType(event), null, true) | ||
| } | ||
| if (!KitUtils.isEmpty(event.productAction) && | ||
| event.productAction.equals( | ||
| Product.PURCHASE, | ||
|
|
@@ -249,7 +281,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, | |
| for (pair in map) { | ||
| e.customAttributes?.put(pair.key, pair.value) | ||
| } | ||
| logEvent(e) | ||
| logBrazeEvent(e) | ||
| messages.add(ReportingMessage.fromEvent(this, event)) | ||
| } catch (e: Exception) { | ||
| Logger.warning("Failed to call logCustomEvent to Appboy kit: $e") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.