UNPKG

rn-pendo-sdk

Version:

Pendo Mobile React Native SDK

1 lines 6.55 kB
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.PendoSDK=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _reactNative=require("react-native");var _common=require("./common");var _pendoLogger=require("./pendoLogger");var _pendoRNN=require("./pendoRNN");var _pendoTypes=require("./pendoTypes");var ReactNativePendo=_reactNative.NativeModules.ReactNativePendo;var PendoSDK=exports.PendoSDK=function(){function PendoSDK(){(0,_classCallCheck2.default)(this,PendoSDK);}return(0,_createClass2.default)(PendoSDK,null,[{key:"setup",value:function setup(appKey,navigationOptions,pendoOptions){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{if(pendoOptions==null){pendoOptions={};}pendoOptions.reactNativeVersion=_common.Utils.reactNativeVersion();pendoOptions.pluginVersion=_common.Utils.pluginVersion();if(pendoOptions.debugMode){this.setDebugMode(true);}if(_common.Utils.isEmpty(navigationOptions)){navigationOptions={library:_pendoTypes.NavigationLibraryType.Other};}if(navigationOptions.library===_pendoTypes.NavigationLibraryType.Other||navigationOptions.library!==_pendoTypes.NavigationLibraryType.ReactNativeNavigation&&navigationOptions.library!==_pendoTypes.NavigationLibraryType.ReactNavigation&&navigationOptions.library!==_pendoTypes.NavigationLibraryType.ExpoRouter){_pendoLogger.Logger.debug('Track Event Mode');navigationOptions.library=_pendoTypes.NavigationLibraryType.Other;}_pendoLogger.Logger.debug(`Pendo Plugin ${pendoOptions.pluginVersion}, React Native: ${pendoOptions.reactNativeVersion}`);ReactNativePendo.setup(appKey,navigationOptions.library,pendoOptions);switch(navigationOptions.library){case _pendoTypes.NavigationLibraryType.ReactNativeNavigation:{_pendoLogger.Logger.info('React Native Navigation Init.');var pendoRNN=new _pendoRNN.PendoRNN(navigationOptions.navigation,navigationOptions.clickableElementsNativeIDsRegex,pendoOptions.isComponentSetStateInvokedRNN);pendoRNN.hook();break;}case _pendoTypes.NavigationLibraryType.ReactNavigation:{_pendoLogger.Logger.info(`React Navigation Init.`);break;}case _pendoTypes.NavigationLibraryType.ExpoRouter:{_pendoLogger.Logger.info(`Expo Router Init.`);break;}default:{_pendoLogger.Logger.info('Track events Init');break;}}}catch(e){_pendoLogger.Logger.error(`setup failed`,e);}}},{key:"track",value:function track(name,params){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{if(name===null||name.length===0){_pendoLogger.Logger.warn(`track failed, Event name is missing`);return;}ReactNativePendo.track(name,params);}catch(e){_pendoLogger.Logger.error(`track failed`,e);}}},{key:"startSession",value:function startSession(visitorId,accountId,visitorData,accountData){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.startSession(visitorId,accountId,visitorData,accountData);}catch(e){_pendoLogger.Logger.error(`startSession failed`,e);}}},{key:"endSession",value:function endSession(){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.endSession();}catch(e){_pendoLogger.Logger.error(`endSession failed`,e);}}},{key:"setVisitorData",value:function setVisitorData(visitorData){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.setVisitorData(visitorData);}catch(e){_pendoLogger.Logger.warn(`setVisitorData failed - ${e.message}`);}}},{key:"setAccountData",value:function setAccountData(accountData){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.setAccountData(accountData);}catch(e){_pendoLogger.Logger.warn(`setAccountData failed - ${e.message}`);}}},{key:"pauseGuides",value:function pauseGuides(dismissGuides){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.pauseGuides(dismissGuides);}catch(e){_pendoLogger.Logger.warn(`pauseGuides failed - ${e.message}`);}}},{key:"resumeGuides",value:function resumeGuides(){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.resumeGuides();}catch(e){_pendoLogger.Logger.warn(`resumeGuides failed - ${e.message}`);}}},{key:"dismissVisibleGuides",value:function dismissVisibleGuides(){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.dismissVisibleGuides();}catch(e){_pendoLogger.Logger.warn(`dismissVisibleGuides failed - ${e.message}`);}}},{key:"getVisitorId",value:(function(){var _getVisitorId=(0,_asyncToGenerator2.default)(function*(){if(!_common.Utils.hasPendoNativeModule(true)){return null;}try{return yield ReactNativePendo.getVisitorId();}catch(e){_pendoLogger.Logger.warn(`getVisitorId failed - ${e.message}`);}return null;});function getVisitorId(){return _getVisitorId.apply(this,arguments);}return getVisitorId;}())},{key:"getAccountId",value:(function(){var _getAccountId=(0,_asyncToGenerator2.default)(function*(){if(!_common.Utils.hasPendoNativeModule(true)){return null;}try{return yield ReactNativePendo.getAccountId();}catch(e){_pendoLogger.Logger.warn(`getAccountId failed - ${e.message}`);}return null;});function getAccountId(){return _getAccountId.apply(this,arguments);}return getAccountId;}())},{key:"getDeviceId",value:(function(){var _getDeviceId=(0,_asyncToGenerator2.default)(function*(){if(!_common.Utils.hasPendoNativeModule(true)){return null;}try{return yield ReactNativePendo.getDeviceId();}catch(e){_pendoLogger.Logger.warn(`getDeviceId failed - ${e.message}`);}return null;});function getDeviceId(){return _getDeviceId.apply(this,arguments);}return getDeviceId;}())},{key:"setDebugMode",value:function setDebugMode(isDebugEnabled){try{_pendoLogger.Logger.setDebugMode(isDebugEnabled);if(_common.Utils.hasPendoNativeModule(false)){ReactNativePendo.setDebugMode(isDebugEnabled);}}catch(e){_pendoLogger.Logger.warn(`setDebugMode failed - ${e.message}`);}}},{key:"sendClickAnalytic",value:function sendClickAnalytic(nativeID){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.sendClickAnalytic(nativeID);}catch(e){_pendoLogger.Logger.warn(`sendClickAnalytic failed - ${e.message}`);}}},{key:"screenContentChanged",value:function screenContentChanged(){if(!_common.Utils.hasPendoNativeModule(true)){return;}try{ReactNativePendo.screenContentChanged();}catch(e){_pendoLogger.Logger.warn(`screenContentChange failed - ${e.message}`);}}}]);}();