-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.js
148 lines (127 loc) · 5.23 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { NativeModules, NativeEventEmitter } from "react-native";
const { RNEmarsysWrapper } = NativeModules;
import Push from "./src/push";
import Inbox from "./src/inbox";
import Predict from "./src/predict";
import Geofence from "./src/geofence";
import InApp, { InlineInAppView } from "./src/inapp";
const Emarsys = {
/* Init ***************************************************************************************************************************************/
/**
* After application setup is finished, you can use `setContact()` method to identify the user with a `contactFieldValue`.
* Without `setContact()` all events will be tracked as anonymous usage.
* @param {number} contactFieldId - Field used for identification.
* @param {string} contactFieldValue - User identification.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
setContact(contactFieldId, contactFieldValue) {
return RNEmarsysWrapper.setContact(contactFieldId, contactFieldValue);
},
/**
* When the user signs out, we should use the `clearContact()` method.
* The method is going to automatically log in an anonymous user instead of the one leaving.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
clearContact() {
return RNEmarsysWrapper.clearContact();
},
/**
* If you want to track custom events, the `trackCustomEvent()` method should be used.
* @param {string} eventName - Name of the tracked custom event.
* @param {Record<string, unknown> | undefined} eventAttributes - Object containing the attributes of the tracked custom event.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
trackCustomEvent(eventName, eventAttributes = null) {
return RNEmarsysWrapper.trackCustomEvent(eventName, eventAttributes);
},
/**
* Register an event handler to react to events triggered by Emarsys.
* @param {(eventName: string, payload: unknown) => void} callback - Function receiving `eventName` & `payload` for
* each event.
* @returns {void}
*/
setEventHandler(callback) {
const eventEmitter = new NativeEventEmitter(RNEmarsysWrapper);
eventEmitter.addListener("handleEvent", function (result) {
callback(result.eventName, result.payload);
});
RNEmarsysWrapper.setEventHandler();
},
/* DeepLink ***********************************************************************************************************************************/
/**
* The Emarsys SDK automatically tracks email link clicks that open the application directly in most use cases, with only one exception: manual tracking is needed.
* @param {string} url - URL to track.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
trackDeepLink(url) {
return RNEmarsysWrapper.trackDeepLink(url);
},
/* Config ***********************************************************************************************************************************/
/**
* Emarsys SDK provides a solution for `applicationCode` change in a convenient way without restarting the SDK.
* @param {string} applicationCode - New `applicationCode` string to change for.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
changeApplicationCode(applicationCode) {
return RNEmarsysWrapper.changeApplicationCode(applicationCode);
},
/**
* Emarsys SDK provides a solution for `merchantId` change in a convenient way without restarting the SDK.
* @param {string} merchantId - New `merchantId` string to change for.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
changeMerchantId(merchantId) {
return RNEmarsysWrapper.changeMerchantId(merchantId);
},
/**
* Provides what is the actual applicationCode set in the SDK.
* @returns {Promise<string>} Currently set `applicationCode` string.
*/
getApplicationCode() {
return RNEmarsysWrapper.getApplicationCode();
},
/**
* Provides what is the actual merchantId set in the SDK.
* @returns {Promise<string>} Currently set `merchantId` string.
*/
getMerchantId() {
return RNEmarsysWrapper.getMerchantId();
},
/**
* Provides what is the actual contactFieldId set in the SDK.
* @returns {Promise<number>} Currently set `contactFieldId` number.
*/
getContactFieldId() {
return RNEmarsysWrapper.getContactFieldId();
},
/**
* Provides what is the actual `hardwareId` set in the SDK.
* @returns {Promise<string>} Current `hardwareId` string.
*/
getHardwareId() {
return RNEmarsysWrapper.getHardwareId();
},
/**
* Provides what is the actual `languageCode` set in the SDK.
* @returns {Promise<string>} Current `languageCode` string.
*/
getLanguageCode() {
return RNEmarsysWrapper.getLanguageCode();
},
/**
* Provides what is the actual `sdkVersion` in the SDK.
* @returns {Promise<string>} String of the current Emarsys SDK version.
*/
getSdkVersion() {
return RNEmarsysWrapper.getSdkVersion();
},
push: Push,
inApp: InApp,
inbox: Inbox,
InlineInAppView,
predict: Predict,
geofence: Geofence,
};
export default Emarsys;
import { version } from "./package.json";
RNEmarsysWrapper.trackCustomEvent("wrapper:init", { type: "react-native", version });