forked from facebookarchive/react-native-fbsdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FBAppEventsLogger.js
185 lines (169 loc) · 5.59 KB
/
FBAppEventsLogger.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
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @flow
* @format
*/
'use strict';
const AppEventsLogger = require('react-native').NativeModules.FBAppEventsLogger;
const {Platform} = require('react-native');
/**
* Controls when an AppEventsLogger sends log events to the server
*/
type AppEventsFlushBehavior =
/**
* Flush automatically: periodically (every 15 seconds or after every 100 events), and
* always at app reactivation. This is the default value.
*/
| 'auto'
/**
* Only flush when AppEventsLogger.flush() is explicitly invoked.
*/
| 'explicit_only';
type Params = {[key: string]: string | number};
/**
* Info about a user to increase chances of matching a Facebook user.
* See https://developers.facebook.com/docs/app-events/advanced-matching for
* more info about the expected format of each field.
*/
type UserData = $ReadOnly<{|
email?: ?string,
firstName?: ?string,
lastName?: ?string,
phone?: ?string,
dateOfBirth?: ?string,
gender?: ?('m' | 'f'),
city?: ?string,
state?: ?string,
zip?: ?string,
country?: ?string,
|}>;
module.exports = {
/**
* Sets the current event flushing behavior specifying when events
* are sent back to Facebook servers.
*/
setFlushBehavior(flushBehavior: AppEventsFlushBehavior) {
AppEventsLogger.setFlushBehavior(flushBehavior);
},
/**
* Logs an event with eventName and optional arguments.
* This function supports the following usage:
* logEvent(eventName: string);
* logEvent(eventName: string, valueToSum: number);
* logEvent(eventName: string, parameters: {[key:string]:string|number});
* logEvent(eventName: string, valueToSum: number, parameters: {[key:string]:string|number});
* See https://developers.facebook.com/docs/app-events/android for detail.
*/
logEvent(eventName: string, ...args: Array<number | Params>) {
let valueToSum = 0;
if (typeof args[0] === 'number') {
valueToSum = args.shift();
}
let parameters = null;
if (typeof args[0] === 'object') {
parameters = args[0];
}
AppEventsLogger.logEvent(eventName, valueToSum, parameters);
},
/**
* Logs a purchase. See http://en.wikipedia.org/wiki/ISO_4217 for currencyCode.
*/
logPurchase(
purchaseAmount: number,
currencyCode: string,
parameters?: ?Params,
) {
AppEventsLogger.logPurchase(purchaseAmount, currencyCode, parameters);
},
/**
* Logs an app event that tracks that the application was open via Push Notification.
*/
logPushNotificationOpen(payload: ?Object) {
AppEventsLogger.logPushNotificationOpen(payload);
},
/**
* Explicitly kicks off flushing of events to Facebook.
*/
flush() {
AppEventsLogger.flush();
},
/**
* Sets a custom user ID to associate with all app events.
* The userID is persisted until it is cleared by passing nil.
*/
setUserID(userID: string | null) {
AppEventsLogger.setUserID(userID);
},
/**
* Returns user id or null if not set
*/
async getUserID(): Promise<?string> {
return await AppEventsLogger.getUserID();
},
/**
* Returns anonymous id or null if not set
*/
async getAnonymousID(): Promise<?string> {
return await AppEventsLogger.getAnonymousID();
},
/**
* Returns advertiser id or null if not set
*/
async getAdvertiserID(): Promise<?string> {
return await AppEventsLogger.getAdvertiserID();
},
/**
* Returns advertiser id or null if not set.
* @platform android
*/
async getAttributionID(): Promise<?string> {
if (Platform.OS === 'ios') {
return null;
}
return await AppEventsLogger.getAttributionID();
},
/**
* Sends a request to update the properties for the current user, set by
* setUserID. You must call setUserID before making this call.
*/
updateUserProperties(parameters: Params) {
AppEventsLogger.updateUserProperties(parameters);
},
/**
* Set additional data about the user to increase chances of matching a Facebook user.
*/
setUserData(userData: UserData) {
AppEventsLogger.setUserData(userData);
},
/**
* For iOS only, sets and sends device token to register the current application for push notifications.
* @platform ios
*/
setPushNotificationsDeviceToken(deviceToken: string) {
AppEventsLogger.setPushNotificationsDeviceToken(deviceToken);
},
/**
* For Android only, sets and sends registration id to register the current app for push notifications.
* @platform Android
*/
setPushNotificationsRegistrationId(registrationId: string) {
AppEventsLogger.setPushNotificationsRegistrationId(registrationId);
},
};