This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
99 lines (88 loc) · 3.49 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
var React = require('react-native');
var GoogleAnalyticsModule = require('react-native').NativeModules.GoogleAnalyticsModule;
// Warp the native module so we can do some pre/post processing to have a cleaner API.
var GoogleAnalytics = {
startTracker: function(id, enableExceptionReporting = true, callback, errorCallback) {
return new Promise(function(resolve, reject) {
if (!id || id.length <= 0) {
console.error('GoogleAnalytics: startTracker: Error: Tracking ID must not be blank.');
if (errorCallback) errorCallback();
reject();
return;
}
GoogleAnalyticsModule.startTracker(id, enableExceptionReporting, (successMessage) => {
if (callback) callback(successMessage);
resolve(successMessage);
}, (errorMessage) => {
if (errorCallback) errorCallback(errorMessage);
reject(errorMessage);
});
});
},
trackView: function(appName = '', screenName = 'default', callback, errorCallback) {
return new Promise(function(resolve, reject) {
GoogleAnalyticsModule.trackView(appName, screenName, (successMessage) => {
if (callback) callback(successMessage);
resolve(successMessage);
}, (errorMessage) => {
if (errorCallback) errorCallback(errorMessage);
reject(errorMessage);
});
});
},
trackEvent: function(category = 'default', action = 'default', label = 'default', value = 0, callback, errorCallback) {
return new Promise(function(resolve, reject) {
GoogleAnalyticsModule.trackEvent(category, action, label, value, (successMessage) => {
if (callback) callback(successMessage);
resolve(successMessage);
}, (errorMessage) => {
if (errorCallback) errorCallback(errorMessage);
reject(errorMessage);
});
});
},
trackException: function(description = 'default', fatal = false, callback, errorCallback) {
return new Promise(function(resolve, reject) {
GoogleAnalyticsModule.trackException(description, fatal, (successMessage) => {
if (callback) callback(successMessage);
resolve(successMessage);
}, (errorMessage) => {
if (errorCallback) errorCallback(errorMessage);
reject(errorMessage);
});
});
},
trackTiming: function(category = 'default', intervalInMillis = 0, name = 'default', label = 'default', callback, errorCallback) {
return new Promise(function(resolve, reject) {
GoogleAnalyticsModule.trackTiming(category, intervalInMillis, name, label, (successMessage) => {
if (callback) callback(successMessage);
resolve(successMessage);
}, (errorMessage) => {
if (errorCallback) errorCallback(errorMessage);
reject(errorMessage);
});
});
},
setUserID: function(userID = 'default', callback, errorCallback) {
return new Promise(function(resolve, reject) {
GoogleAnalyticsModule.setUserID(userID, (successMessage) => {
if (callback) callback(successMessage);
resolve(successMessage);
}, (errorMessage) => {
if (errorCallback) errorCallback(errorMessage);
reject(errorMessage);
});
});
},
isGooglePlayServicesAvailable: function(callback) {
return new Promise(function(resolve, reject) {
GoogleAnalyticsModule.isGooglePlayServicesAvailable((availability) => {
if (callback) callback(availability);
resolve(availability);
});
});
},
nativeModule: GoogleAnalyticsModule
}
module.exports = GoogleAnalytics;