forked from AppsFlyerSDK/appsflyer-react-native-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·313 lines (270 loc) · 9.73 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import { NativeEventEmitter, NativeModules } from "react-native";
const { RNAppsFlyer } = NativeModules;
const appsFlyer = {};
const eventsMap = {};
const appsFlyerEventEmitter = new NativeEventEmitter(RNAppsFlyer);
function initSdkCallback(options, successC, errorC) {
return RNAppsFlyer.initSdk(options, successC, errorC);
}
function initSdkPromise(options): Promise<string> {
return RNAppsFlyer.initSdkWithPromise(options);
}
function initSdk(options, success, error): Promise<string> {
options.onInstallConversionDataListener = eventsMap["onInstallConversionData"]
? true
: false;
if (success && error) {
//initSdk is a callback function
initSdkCallback(options, success, error);
} else if (!success) {
//initSdk is a promise function
return initSdkPromise(options);
}
}
appsFlyer.initSdk = initSdk;
function trackEventCallback(eventName, eventValues, successC, errorC) {
return RNAppsFlyer.trackEvent(eventName, eventValues, successC, errorC);
}
function trackEventPromise(eventName, eventValues): Promise<string> {
return RNAppsFlyer.trackEventWithPromise(eventName, eventValues);
}
function trackEvent(eventName, eventValues, success, error): Promise<string> {
if (success && error) {
//trackEvent is a callback function
trackEventCallback(eventName, eventValues, success, error);
} else if (!success) {
//trackEvent is a promise function
return trackEventPromise(eventName, eventValues);
}
}
appsFlyer.trackEvent = trackEvent;
/**
* iOS only
*/
appsFlyer.trackAppLaunch = () => {
return RNAppsFlyer.trackAppLaunch();
};
/**
* Manually record the location of the user
*
* @param longitude latitude as double.
* @param latitude latitude as double.
* @callback callback success callback function.
* @platform ios only
*/
appsFlyer.trackLocation = (longitude, latitude, callback) => {
return RNAppsFlyer.trackLocation(longitude, latitude, callback);
};
/**
* Set the user emails and encrypt them.
*
* @param options latitude as double.
* @callback successC success callback function.
* @callback errorC error callback function.
*/
appsFlyer.setUserEmails = (options, successC, errorC) => {
return RNAppsFlyer.setUserEmails(options, successC, errorC);
};
/**
* Set additional data to be sent to AppsFlyer.
*
* @param additionalData additional data Dictionary.
* @callback successC success callback function.
*/
appsFlyer.setAdditionalData = (additionalData, successC) => {
return RNAppsFlyer.setAdditionalData(additionalData, successC);
};
/**
* Get AppsFlyer's unique device ID is created for every new install of an app.
*
* @callback callback function that returns (error,uid)
*/
appsFlyer.getAppsFlyerUID = callback => {
return RNAppsFlyer.getAppsFlyerUID(callback);
};
appsFlyer.sendDeepLinkData = callback => {
return RNAppsFlyer.sendDeepLinkData(callback);
};
/**
* @deprecated
*/
appsFlyer.setGCMProjectNumber = (gcmProjectNumber, successC, errorC) => {
return RNAppsFlyer.setGCMProjectNumber(gcmProjectNumber, successC, errorC);
};
/**
* For Android only (GCM). iOS uses 'didRegisterForRemoteNotificationsWithDeviceToken' in AppDelegate.m
*
*/
appsFlyer.enableUninstallTracking = (gcmProjectNumber, successC) => {
return RNAppsFlyer.enableUninstallTracking(gcmProjectNumber, successC);
};
/**
* Manually pass the Firebase / GCM Device Token for Uninstall measurement.
*
* @param token Firebase Device Token.
* @callback successC success callback function.
* @platform android
*/
appsFlyer.updateServerUninstallToken = (token, successC) => {
return RNAppsFlyer.updateServerUninstallToken(token, successC);
};
/**
* Setting your own customer ID enables you to cross-reference your own unique ID with AppsFlyer’s unique ID and the other devices’ IDs.
* This ID is available in AppsFlyer CSV reports along with Postback APIs for cross-referencing with your internal IDs.
*
* @param {string} userId Customer ID for client.
* @callback successC success callback function.
*/
appsFlyer.setCustomerUserId = (userId, successC) => {
return RNAppsFlyer.setCustomerUserId(userId, successC);
};
/**
* Once this API is invoked, our SDK no longer communicates with our servers and stops functioning.
* In some extreme cases you might want to shut down all SDK activity due to legal and privacy compliance.
* This can be achieved with the stopTracking API.
*
* @param {boolean} isStopTracking boolean should SDK be stopped.
* @callback successC success callback function.
*/
appsFlyer.stopTracking = (isStopTracking, successC) => {
return RNAppsFlyer.stopTracking(isStopTracking, successC);
};
/**
* Opt-out of collection of IMEI.
* If the app does NOT contain Google Play Services, device IMEI is collected by the SDK.
* However, apps with Google play services should avoid IMEI collection as this is in violation of the Google Play policy.
*
* @param {boolean} isCollect boolean, false to opt out.
* @callback successC success callback function.
* @platform android
*/
appsFlyer.setCollectIMEI = (isCollect, successC) => {
return RNAppsFlyer.setCollectIMEI(isCollect, successC);
};
/**
* Opt-out of collection of Android ID.
* If the app does NOT contain Google Play Services, Android ID is collected by the SDK.
* However, apps with Google play services should avoid Android ID collection as this is in violation of the Google Play policy.
*
* @param {boolean} isCollect boolean, false to opt out.
* @callback successC success callback function.
* @platform android
*/
appsFlyer.setCollectAndroidID = (isCollect, successC) => {
return RNAppsFlyer.setCollectAndroidID(isCollect, successC);
};
/**
* Set the OneLink ID that should be used for User-Invite-API.
* The link that is generated for the user invite will use this OneLink as the base link.
*
* @param {string} oneLinkID OneLink ID obtained from the AppsFlyer Dashboard.
* @callback successC success callback function.
*/
appsFlyer.setAppInviteOneLinkID = (oneLinkID, successC) => {
return RNAppsFlyer.setAppInviteOneLinkID(oneLinkID, successC);
};
/**
* The LinkGenerator class builds the invite URL according to various setter methods which allow passing on additional information on the click.
* @see https://support.appsflyer.com/hc/en-us/articles/115004480866-User-invite-attribution-
*
* @param parameters Dictionary.
* @callback success success callback function.
* @callback error error callback function.
*/
appsFlyer.generateInviteLink = (parameters, success, error) => {
return RNAppsFlyer.generateInviteLink(parameters, success, error);
};
/**
* To attribute an impression use the following API call.
* Make sure to use the promoted App ID as it appears within the AppsFlyer dashboard.
*
* @param appId promoted App ID.
* @param campaign cross promotion campaign.
*/
appsFlyer.trackCrossPromotionImpression = (appId, campaign) => {
return RNAppsFlyer.trackCrossPromotionImpression(appId, campaign);
};
/**
* Use the following API to attribute the click and launch the app store's app page.
*
* @param appId promoted App ID.
* @param campaign cross promotion campaign.
* @param params additional user params.
*/
appsFlyer.trackAndOpenStore = (appId, campaign, params) => {
return RNAppsFlyer.trackAndOpenStore(appId, campaign, params);
};
/**
* Setting user local currency code for in-app purchases.
* The currency code should be a 3 character ISO 4217 code. (default is USD).
* You can set the currency code for all events by calling the following method.
* @param currencyCode
* @param successC success callback function.
*/
appsFlyer.setCurrencyCode = (currencyCode, successC) => {
return RNAppsFlyer.setCurrencyCode(currencyCode, successC);
};
/**
* Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking)
* @param callback: contains fields:
* status: success/failure
* type:
* onAppOpenAttribution
* onInstallConversionDataLoaded
* onAttributionFailure
* onInstallConversionFailure
* data: metadata,
* @example {"status":"success","type":"onInstallConversionDataLoaded","data":{"af_status":"Organic","af_message":"organic install"}}
*
* @returns {remove: function - unregister listener}
*/
appsFlyer.onInstallConversionData = callback => {
//console.log("onInstallConversionData is called" );
const listener = appsFlyerEventEmitter.addListener(
"onInstallConversionDataLoaded",
_data => {
if (callback && typeof callback === typeof Function) {
try {
let data = JSON.parse(_data);
callback(data);
} catch (_error) {
//throw new AFParseJSONException("...");
//TODO: for today we return an error in callback
callback(new AFParseJSONException("Invalid data structure", _data));
}
}
}
);
eventsMap["onInstallConversionData"] = listener;
// unregister listener (suppose should be called from componentWillUnmount() )
return function remove() {
listener.remove();
};
};
appsFlyer.onAppOpenAttribution = callback => {
//console.log("onAppOpenAttribution is called" );
const listener = appsFlyerEventEmitter.addListener(
"onAppOpenAttribution",
_data => {
if (callback && typeof callback === typeof Function) {
try {
let data = JSON.parse(_data);
callback(data);
} catch (_error) {
callback(new AFParseJSONException("Invalid data structure", _data));
}
}
}
);
eventsMap["onAppOpenAttribution"] = listener;
// unregister listener (suppose should be called from componentWillUnmount() )
return function remove() {
listener.remove();
};
};
function AFParseJSONException(_message, _data) {
this.message = _message;
this.data = _data;
this.name = "AFParseJSONException";
}
export default appsFlyer;