forked from dangerfarms/react-native-batch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (23 loc) · 1007 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true,
});
var _reactNative = require('react-native');
var Batch = _reactNative.NativeModules.RNBatch;
var eventNameRegex = /^[a-z0-9_]*$/;
Batch.trackEvent = function trackEvent(eventName, label, data) {
if (!eventName || eventName.length > 30 || !eventNameRegex.test(eventName)) {
throw(new Error('Batch event name must be [1-30] char long, can only contain lowercase letters, ' +
'numbers, and underscore'));
}
var eventOnly = eventName && !label && !data;
var eventWithLabel = eventName && label && !data;
var eventWithLabelAndData = eventName && label && data;
if (eventOnly) {
return Batch.trackEventWithName(eventName.toString());
} else if (eventWithLabel) {
return Batch.trackEventWithLabel(eventName.toString(), label.toString());
}
return Batch.trackEventWithLabelAndData(eventName.toString(), label.toString(), data);
};
exports.default = Batch;