forked from AppsFlyerSDK/appsflyer-react-native-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (77 loc) · 2.94 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
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.trackLocation = (longitude, latitude, callback) => {
return RNAppsFlyer.trackLocation(longitude, latitude, callback);
};
appsFlyer.trackEvent = (eventName, eventValues, successC, errorC) => {
return RNAppsFlyer.trackEvent(eventName, eventValues, successC, errorC);
};
appsFlyer.getAppsFlyerUID = (callback) => {
return RNAppsFlyer.getAppsFlyerUID(callback);
};
/**
* For Android only (Google API). iOS uses 'didRegisterForRemoteNotificationsWithDeviceToken' in AppDelegate.m
*/
appsFlyer.setGCMProjectID = (gcmProjectId, successC, errorC) => {
return RNAppsFlyer.setGCMProjectID(gcmProjectId, successC, errorC);
};
appsFlyer.setCustomerUserId = (userId, successC,) => {
return RNAppsFlyer.setCustomerUserId(userId, successC);
};
appsFlyer.trackAppLaunch = () => {
RNAppsFlyer.trackAppLaunch();
}
/**
* 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;