package co.ab180.airbridge.reactnative.module import android.util.Log import co.ab180.airbridge.Airbridge import co.ab180.airbridge.common.AirbridgeEventType import co.ab180.airbridge.common.AirbridgeStoreInAppPurchase import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap internal class EventInteractor( reactContext: ReactApplicationContext? ) : ReactContextBaseJavaModule(reactContext) { override fun getName(): String = "EventInteractor" @ReactMethod fun trackEvent(category: String, semanticAttributes: ReadableMap?, customAttributes: ReadableMap?) { Airbridge.trackEvent( category = category, semanticAttributes = semanticAttributes?.toHashMap(), customAttributes = customAttributes?.toHashMap() ) } @ReactMethod fun setAdditionalEventAttributes(types: ReadableArray, semanticAttributes: ReadableMap?, customAttributes: ReadableMap?) { val eventTypes = types.toArrayList().mapNotNull { type -> (type as? String)?.let { convertAirbridgeEventType(it) } } if (eventTypes.isEmpty()) { return } Airbridge.setAdditionalEventAttributes( eventTypes, semanticAttributes?.toHashMap(), customAttributes?.toHashMap() ) } @ReactMethod fun trackStoreInAppPurchaseEvent(purchase: ReadableMap, semanticAttributes: ReadableMap?, customAttributes: ReadableMap?) { Airbridge.trackStoreInAppPurchaseEvent( AirbridgeStoreInAppPurchase(purchase.toHashMap()), semanticAttributes?.toHashMap(), customAttributes?.toHashMap() ) } private fun convertAirbridgeEventType(type: String): AirbridgeEventType? { return AirbridgeEventType.values().firstOrNull { it.name == type } ?: run { Log.w("AirbridgeReactNative", "Unknown event type: $type") null } } }