UNPKG

vwo-insights-react-native-sdk

Version:

VWO Insights helps you analyze user behavior in your application based on interactions such as application launch, taps, scrolls, and flings. By attributing these actions to critical business events like purchases and sign-ups (which are considered conver

98 lines 3.62 kB
import { NativeModules, Platform, NativeEventEmitter } from 'react-native'; import packageJson from '../package.json'; const LINKING_ERROR = `The package 'vwo-insights-react-native-sdk' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const VwoInsightsReactNativeSdk = NativeModules.VwoInsightsReactNativeSdk ? NativeModules.VwoInsightsReactNativeSdk : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); export function addSessionRefreshListener(callback) { const MyNativeEvents = new NativeEventEmitter(NativeModules.VwoInsightsReactNativeSdk); return MyNativeEvents.addListener('onSessionRefresh', callback); } export function removeSessionRefreshListener() { const MyNativeEvents = new NativeEventEmitter(NativeModules.VwoInsightsReactNativeSdk); MyNativeEvents.removeAllListeners('onSessionRefresh'); } export function config(accountID, AppID, userID) { VwoInsightsReactNativeSdk.sdkVersion(packageJson.version); return Platform.OS == 'ios' ? VwoInsightsReactNativeSdk.config(accountID, AppID, userID) : null; } export function startRecording() { return VwoInsightsReactNativeSdk.startRecording(); } export function stopRecording() { return VwoInsightsReactNativeSdk.stopRecording(); } export function setScreenName(state) { const screenName = getActiveRouteName(state); setTimeout(() => { return VwoInsightsReactNativeSdk.setScreenName(screenName == 'Unknown' ? state : screenName); }, Platform.OS == 'ios' ? 0 : 300); } export function setScreenViewed(screenName) { setTimeout(() => { return VwoInsightsReactNativeSdk.setScreenName(screenName); }, Platform.OS == 'ios' ? 0 : 300); } export function customAttribute(data) { VwoInsightsReactNativeSdk.customAttribute(data); } export function customEvent(eventName, data) { const { booleanValues, nonBooleanValues } = separateObjects(data); return Platform.OS == 'ios' ? VwoInsightsReactNativeSdk.customEvent(eventName, nonBooleanValues, booleanValues) : VwoInsightsReactNativeSdk.customEvent(eventName, data); } export function customVariable(data) { return Platform.OS == 'ios' ? VwoInsightsReactNativeSdk.customVariable(data) : VwoInsightsReactNativeSdk.customVariable(data); } const separateObjects = data => { const booleanValues = {}; const nonBooleanValues = {}; for (const key in data) { if (typeof data[key] === 'boolean') { booleanValues[key] = data[key]; } else { nonBooleanValues[key] = data[key]; } } return { booleanValues, nonBooleanValues }; }; const getActiveRouteName = state => { if (!state || typeof state.index !== 'number') { return 'Unknown'; } const route = state.routes[state.index]; if (route.state) { return getActiveRouteName(route?.state); } return route.name; }; export async function getSessionURL(source) { try { const sessionURL = await VwoInsightsReactNativeSdk.getSessionURL(source); return sessionURL; } catch (error) { console.error('Error in getSessionURL:', error); throw error; } } export function enableVWOIntegrations(callback) { // Call native module method passing the callback return Platform.OS === 'ios' ? VwoInsightsReactNativeSdk.enableVWOIntegrations(callback) : null; } export function pauseRecording() { return VwoInsightsReactNativeSdk.pauseRecording(); } export function resumeRecording() { return VwoInsightsReactNativeSdk.resumeRecording(); } //# sourceMappingURL=index.js.map