@literal.ai/literator-react-native
Version:
In minutes, see all your screens automatically mapped into user flows and annotated with analytics events.
44 lines (35 loc) • 1.65 kB
JavaScript
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { NativeModules, Platform } from 'react-native';
const LINKING_ERROR = `The package 'literator-react-native' 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 managed workflow\n';
const LiteratorModule = NativeModules.LiteratorModule ? NativeModules.LiteratorModule : new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
}
});
const logMessage = message => {
console.log('Literator-React => ' + message);
};
export default class Literator {
static async start(accessToken) {
if (!Literator.started) {
logMessage('start()');
const promiseResult = LiteratorModule.start(accessToken);
Literator.started = true;
return promiseResult;
}
return Promise.resolve(false);
}
static async sendAnalytics(eventName) {
let properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let tag = arguments.length > 2 ? arguments[2] : undefined;
let debugProps = JSON.stringify(properties);
logMessage(`sendAnalytics(${eventName} => ${debugProps}), tag=${tag}`); // return Promise.resolve(true);
const promiseResult = LiteratorModule.sendAnalytics(eventName, properties, tag);
return promiseResult;
}
}
_defineProperty(Literator, "started", false);
//# sourceMappingURL=index.js.map