forked from G2Jose/react-native-appsflyer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·138 lines (107 loc) · 3.9 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
import { NativeModules } from 'react-native';
import { NativeAppEventEmitter } from 'react-native';
const { RNAppsFlyer } = NativeModules;
const appsFlyer = {};
const eventsMap = {};
appsFlyer.initSdk = (options, successC, errorC) => {
// console.log("initSdk: " + eventsMap['onInstallConversionData']);
options.onInstallConversionDataListener = (eventsMap['onInstallConversionData']) ? true: false;
return RNAppsFlyer.initSdk(options, successC, errorC);
};
/**
* iOS only
*/
appsFlyer.trackAppLaunch = () => {
return RNAppsFlyer.trackAppLaunch();
}
appsFlyer.trackLocation = (longitude, latitude, callback) => {
return RNAppsFlyer.trackLocation(longitude, latitude, callback);
};
appsFlyer.trackEvent = (eventName, eventValues, successC, errorC) => {
return RNAppsFlyer.trackEvent(eventName, eventValues, successC, errorC);
};
appsFlyer.setUserEmails = (options, successC, errorC) => {
return RNAppsFlyer.setUserEmails(options, successC, errorC);
};
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);
};
/**
* For Android only (GCM or Firebase).
*/
appsFlyer.updateServerUninstallToken = (token, successC) => {
return RNAppsFlyer.updateServerUninstallToken(token, successC);
};
appsFlyer.setCustomerUserId = (userId, successC) => {
return RNAppsFlyer.setCustomerUserId(userId, successC);
};
/**
*GDPR
*/
appsFlyer.stopTracking = (isStopTracking, successC) => {
return RNAppsFlyer.stopTracking(isStopTracking, successC);
};
appsFlyer.setCollectIMEI = (isCollect, successC) => {
return RNAppsFlyer.setCollectIMEI(isCollect, successC);
};
appsFlyer.setCollectAndroidID = (isCollect, successC) => {
return RNAppsFlyer.setCollectAndroidID(isCollect, 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 = NativeAppEventEmitter.addListener('onInstallConversionData',
(_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();
};
};
function AFParseJSONException(_message, _data) {
this.message = _message;
this.data = _data;
this.name = "AFParseJSONException";
}
export default appsFlyer;