UNPKG

zence-marketing-react

Version:

zence-marketing-react is a React Native Android SDK designed to streamline event tracking and notifications for mobile applications. This SDK enables seamless integration with Android / iOS apps, capturing user actions like clicks, add-to-cart, purchases,

55 lines (48 loc) 1.66 kB
// Servies import AsyncStorage from "@react-native-community/async-storage"; import { postEventData } from "./src/apiConfig/api"; import PredefinedEvents from "./src/events/predefinedEvents"; class ZenceMarketing { // Method for calling any predefined event trigger(eventName, data) { PredefinedEvents.handleEvent(eventName, data); } // Custom event handler async event(eventName, data = {}) { const deviceId = await AsyncStorage.getItem("deviceId"); const appId = await AsyncStorage.getItem("appId"); const appName = await AsyncStorage.getItem("appName"); const userId = await AsyncStorage.getItem("userId"); const userName = await AsyncStorage.getItem("userName"); const webSiteUrl = await AsyncStorage.getItem("webSiteUrl"); const event = { name: eventName, data: data, timestamp: new Date().toISOString(), deviceId: deviceId, appId: appId, appName: appName, userId: userId?.length > 0 ? userId : null, userName: userName?.length > 0 ? userName : null, webSiteUrl: webSiteUrl, }; return this.sendCustomEvent(event); } // Send custom event to the API async sendCustomEvent(event) { if (!event.name) { console.error("Event name is required"); return; } try { const response = await postEventData(event); console.log(`Event '${event.name}' sent successfully`); return response; } catch (error) { console.error(`Failed to send event '${event.name}':`, error); } } } // Export a single instance of EasyRewards class const zenceMarketing = new ZenceMarketing(); export default zenceMarketing;