import {NativeModules, Platform} from 'react-native'; import { BloodProperties, CartProperties, CheckoutProperties, DeliveryProperties, DrugProperties, GroceryProperties, ItemProperties, ItemReportProperties, ItemRequestProperties, ItemVerificationProperties, MedicalEquipmentProperties, OxygenProperties, FacilityProperties, ItemImpressionModel, CancelCheckoutProperties } from "./typings"; const {CfLogECom} = NativeModules; /** * logItemEvent refers to an item in E-commerce. It can be called when a user taps on an item to * view it in full screen and also when a user taps on the description of the item to view more * details. This event refers to the item view log that reflects the user has seen specific * item or view its details. * * @param action is required to set Type for the type of log in this case, if a * user is viewing an item or its details. * @param item required to pass the whole item as a JSON String object as well. * You can use the POJO ItemModel to parse the data in the required * format and pass that to this function as a string to log the event. * @param search_id is used to associate the search id with the item being viewed by * the user. It is required to track if the item is a result of some * search performed by the user in the app. * @param catalogObject is used to set the drug catalog for the item being viewed. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logItemEvent = (properties: ItemProperties, catalogObject: any) => { console.log(properties) if (Platform.OS === 'android') { var catalogProperties = null if (catalogObject != null) { catalogProperties = JSON.stringify(catalogObject) } CfLogECom.logItemEvent(properties.action, JSON.stringify(properties.item), catalogProperties, null, false) } else if (Platform.OS === 'ios') { var catalogProperties = null if (catalogObject != null) { catalogProperties = JSON.stringify(catalogObject) } CfLogECom.logItemEvent(properties.action, JSON.stringify(properties.item), catalogProperties, false) } } /** * logCartEvent is used to log the events related to the cart. You can use this event to log * When an item was added or removed from the cart. * * @param id used to log the cartId the event is logged for. It is recommended to * include the cartIds for the defined list types so that they can be * tracked. * @param cartAction is required to pass the actions for cart the logged is triggered on. * By default, the SDK provides 2 main list actions for e-commerce apps. * Which includes addItem and removeItem * @param item is used to pass the whole item as a JSON String object as well. You * can use the POJO ItemModel to parse the data in the required format * and pass that to this function as a string to log the event. * @param cart_price is required to log the total price for the cart being logged. Details * about the cart are to be provided in the catalog. * @param currency is required to log the currency for cart price being logged. Details * about the cart are to be provided in the catalog. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logCartEvent = (properties: CartProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logCartEvent(properties.id, properties.action, JSON.stringify(properties.item), properties.cart_price, properties.currency, null, false) }else if (Platform.OS === 'ios') { CfLogECom.logCartEvent(properties.id, properties.action, JSON.stringify(properties.item), properties.cart_price, properties.currency, false) } } /** * logCheckoutEvent is to track the success/failed use cases for the order placement. it can track * kpis for the order being placed based on the ratio of how many orders were successfully and * how many were not and what are the order aspects. * * @param id is for the orderId being placed. In case of not being placed and not * having a valid orderId, you can pass the cartId instead. * @param cartId is for the cart being checked out. * @param is_successful is for the order if it was placed successfully or not. * @param cart_price is required to log the total price of the order being logged. * Price format should be in accordance with the currency selected. * @param currency is required to log the currency for the order logged. Currency * Should be in ISO 4217 format. For ease, SDK provides the enums * CountryCode to log the currency so that it would be easy to log. * You can also use the string function to provide the currency. * @param shop_mode is required to log the mode for the shopping, delivery or pickup. * @param items_list can be used to add the item being ordered to the checkout list. * Order items should be in a valid format. With elements of the * order Object as: OrderItem(itemID, price, quantity, promoId) * Promo Id can be an empty string or no value at all if the item * does not have a promo offer that is obtained by the user. You can * add multiple addOrder functions to one checkout event to include * all the items in order. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logCheckoutEvent = (properties: CheckoutProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logCheckoutEvent(properties.id, properties.cart_id, properties.is_successful, properties.cart_price, properties.currency, properties.shop_mode, JSON.stringify(properties.items), null, false) }else if (Platform.OS === 'ios') { CfLogECom.logCheckoutEvent(properties.id, properties.cart_id, properties.is_successful, properties.cart_price, properties.currency, properties.shop_mode, JSON.stringify(properties.items), false) } } /** * logDeliveryEvent is used to log the status for the delivery. It can be used to log the * delivered status of the order or partial order. Details about the items in the specific * delivery should be provided in the catalog. * * @param id is required to associate the rating obtained for the order. OrderId * Should be a valid orderId and can be tracked from the catalog. * @param action is required to set the delivery action for the log. For the order * being prepared for delivery or left the shipment center or * delivered to the customer. * @param delivery_id is required to associate the rating obtained for the order. * deliveryId should be a valid deliveryId and can be tracked from the * catalog for the items in that specific delivery. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logDeliveryEvent = (properties: DeliveryProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logDeliveryEvent(properties.order_id, properties.action, properties.id, properties.is_urgent, properties.est_delivery_ts, properties.delivery_coordinates, properties.dispatch_coordinates, null, false) }else if (Platform.OS === 'ios') { CfLogECom.logDeliveryEvent(properties.order_id, properties.action, properties.id, properties.is_urgent, properties.est_delivery_ts, properties.delivery_coordinates, properties.dispatch_coordinates, false) } } /** * logCancelCheckoutEvent is used to log the event when the order/cart is canceled. * * @param id can be used to log the orderId and cartId the event is logged for. * This should be in accordance to the type provided in the log and * should represent the actual element being cancelled/discarded. * @param type is the type of checkout element being canceled, cart or order * @param itemsList is required to provide the list of item types that are present * in the order being cancelled. * @param reason is required to define the reason for which the item is being cancelled. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logCancelCheckoutEvent = (properties: CancelCheckoutProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logCancelCheckoutEvent(properties.id, properties.type, JSON.stringify(properties.items), properties.reason, null, false) }else if (Platform.OS === 'ios') { CfLogECom.logCancelCheckoutEvent(properties.id, properties.type, JSON.stringify(properties.items), properties.reason, false) } } /** * logItemReportEvent is used to log the event an item is reported. * * @param itemObject is for the providing item Id and type for the item in question.The * object should be based on the ItemTypeModel or a string that can * be converted to the object with proper param names. * @param storeObject is for the providing store object details for the item report if any. * The object should be based on the StoreObject or a string that can be * converted to the object with proper param names. * @param reportObject is for the providing report object details for the item report if any. * The object should be based on the ReportObject or a string that can * be converted to the object with proper param names. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logItemReportEvent = (properties: ItemReportProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logItemReportEvent(JSON.stringify(properties.item), JSON.stringify(properties.store_info), JSON.stringify(properties.report_info), null, false) }else if (Platform.OS === 'ios') { CfLogECom.logItemReportEvent(JSON.stringify(properties.item), JSON.stringify(properties.store_info), JSON.stringify(properties.report_info), false) } } /** * logItemRequestEvent is used to log the event an item is requested. * * @param itemName is for the providing Item name requested by the user. * @param manufacturer is for the providing manufacturer for the item requested by the user. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logItemRequestEvent = (properties: ItemRequestProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logItemRequestEvent(properties.request_id, properties.item_name, properties.manufacturer, null, false) }else if (Platform.OS === 'ios') { CfLogECom.logItemRequestEvent(properties.request_id, properties.item_name, properties.manufacturer, false) } } /** * logItemVerificationEvent is used to log the event an item is verified/scanned by the user. * * @param scanChannel is for the providing scan channel used for verification. * @param scanType is for the providing scan Type used for verification. * @param isSuccessful is for the providing if verification was successful or not. * @param itemInfo is for the providing item info details returned by the verification. * The object should be based on the ItemInfoObject or a string that can * be converted to the object with proper param names. * @param meta is to send any other data you want to send with the ingest, can be null. * @param updateImmediately is default set to true, you can use that to log events when the app * goes in the background or closed. */ const logItemVerificationEvent = (properties: ItemVerificationProperties) => { console.log(properties) if (Platform.OS === 'android') { CfLogECom.logItemVerificationEvent(properties.scan_channel, properties.scan_type, properties.is_successful, JSON.stringify(properties.item_info), null, false) }else if (Platform.OS === 'ios') { CfLogECom.logItemVerificationEvent(properties.scan_channel, properties.scan_type, properties.is_successful, JSON.stringify(properties.item_info), false) } } /** * logItemImpressionEvent is used to log the impression on items in a list that can be on home screen or as * a search result. In case of a search result, the search Id returned by the search log should be * included in the log to map the results. * * @param collection_id is required to associate the current recycler impression listener to a * unique UI element. * @param visible_item_indices is the list if current visible elements at any time on a screen, provided * by {onVisibleIndicesChanged} from the recyclerListView * @param content_list is the mapped list of elements for the impression view to look into. * This should be mapped with Item Model provided by the SDK * @param search_id is the for use case when the recyclerListView is for the search results * and searchId should be the one provided by the search log. */ const logItemImpressionEvent = (collection_id: string, visible_item_indices: any, content_list: any) => { if (Platform.OS === 'android') { var visibleContent = visible_item_indices.map((x: any) => content_list[x]); console.log(JSON.stringify(visibleContent)) CfLogECom.logItemImpressionEvent(collection_id, JSON.stringify(visibleContent)); }else if (Platform.OS === 'ios') { var visibleContent = visible_item_indices.map((x: any) => content_list[x]); console.log(JSON.stringify(visibleContent)) CfLogECom.logItemImpressionEvent(collection_id, JSON.stringify(visibleContent)); } } const logSelfItemImpressionEvent = (collection_id: string, content_list: ItemImpressionModel) => { console.log(JSON.stringify(content_list)) if (Platform.OS === 'android') { CfLogECom.logItemImpressionEvent(collection_id, JSON.stringify(content_list)); }else if (Platform.OS === 'ios') { CfLogECom.logItemImpressionEvent(collection_id, JSON.stringify(content_list),); } } /** * Drug catalog values * * @param itemId Drug id in the system. * @param drugCatalogModel Props for the drug item. */ const updateDrugCatalog = (itemId: string, drugCatalogModel: DrugProperties) => { console.log(drugCatalogModel) if (Platform.OS === 'android') { CfLogECom.updateDrugCatalog(itemId, JSON.stringify(drugCatalogModel)) }else if (Platform.OS === 'ios') { CfLogECom.updateDrugCatalog(itemId, JSON.stringify(drugCatalogModel)) } } /** * Grocery catalog values * * @param itemId Grocery id in the system * @param groceryCatalogModel Props for the grocery item */ const updateGroceryCatalog = (itemId: string, groceryCatalogModel: GroceryProperties) => { console.log(groceryCatalogModel) if (Platform.OS === 'android') { CfLogECom.updateGroceryCatalog(itemId, JSON.stringify(groceryCatalogModel)) }else if (Platform.OS === 'ios') { CfLogECom.updateGroceryCatalog(itemId, JSON.stringify(groceryCatalogModel)) } } /** * Blood catalog values * * @param itemId Item id in the system * @param bloodCatalogModel Props for the blood item */ const updateBloodCatalog = (itemId: string, bloodCatalogModel: BloodProperties) => { console.log(bloodCatalogModel) if (Platform.OS === 'android') { CfLogECom.updateBloodCatalog(itemId, JSON.stringify(bloodCatalogModel)) }else if (Platform.OS === 'ios') { CfLogECom.updateBloodCatalog(itemId, JSON.stringify(bloodCatalogModel)) } } /** * Oxygen catalog values * * @param itemId Item id in the system * @param oxygenCatalogModel Props for the Oxygen item */ const updateOxygenCatalog = (itemId: string, oxygenCatalogModel: OxygenProperties) => { console.log(oxygenCatalogModel) if (Platform.OS === 'android') { CfLogECom.updateOxygenCatalog(itemId, JSON.stringify(oxygenCatalogModel)) }else if (Platform.OS === 'ios') { CfLogECom.updateOxygenCatalog(itemId, JSON.stringify(oxygenCatalogModel)) } } /** * Medical Equipment catalog values * * @param itemId Item id in the system * @param medicalEquipmentCatalogModel Props for the Medical Equipment item */ const updateMedicalEquipmentCatalog = (itemId: string, medicalEquipmentCatalogModel: MedicalEquipmentProperties) => { console.log(medicalEquipmentCatalogModel) if (Platform.OS === 'android') { CfLogECom.updateMedicalEquipmentCatalog(itemId, JSON.stringify(medicalEquipmentCatalogModel)) }else if (Platform.OS === 'ios') { CfLogECom.updateMedicalEquipmentCatalog(itemId, JSON.stringify(medicalEquipmentCatalogModel)) } } /** * Facility catalog values * * @param facilityId Facility id in the system * @param facilityCatalogModel Props for the facility element */ const updateFacilityCatalog = (facilityId: string, facilityCatalogModel: FacilityProperties) => { console.log(facilityCatalogModel) if (Platform.OS === 'android') { CfLogECom.updateFacilityCatalog(facilityId, JSON.stringify(facilityCatalogModel)) }else if (Platform.OS === 'ios') { CfLogECom.updateFacilityCatalog(facilityId, JSON.stringify(facilityCatalogModel)) } } export default { logItemEvent, logCartEvent, logCheckoutEvent, logDeliveryEvent, logItemImpressionEvent, logSelfItemImpressionEvent, logCancelCheckoutEvent, logItemReportEvent, logItemRequestEvent, logItemVerificationEvent, updateGroceryCatalog, updateDrugCatalog, updateBloodCatalog, updateOxygenCatalog, updateMedicalEquipmentCatalog, updateFacilityCatalog }