mixpanel-react-native 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -11
- package/__tests__/index.test.js +181 -61
- package/android/bin/.settings/org.eclipse.buildship.core.prefs +1 -1
- package/android/bin/build.gradle +8 -1
- package/index.js +896 -833
- package/package.json +56 -56
- package/release.py +3 -3
package/index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {Platform, NativeModules} from "react-native";
|
|
4
4
|
import packageJson from "./package.json";
|
|
5
|
-
const {
|
|
5
|
+
const {MixpanelReactNative} = NativeModules;
|
|
6
6
|
|
|
7
7
|
if (!MixpanelReactNative) {
|
|
8
|
-
|
|
8
|
+
throw new Error(`mixpanel-react-native: MixpanelReactNative is null.
|
|
9
9
|
Please follow the guide on the Github repository: https://github.com/mixpanel/mixpanel-react-native.`);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const DevicePlatform = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
13
|
+
Unknown: "Unknown",
|
|
14
|
+
Android: "android",
|
|
15
|
+
iOS: "ios",
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
const ERROR_MESSAGE = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
INVALID_OBJECT: " is not a valid json object",
|
|
20
|
+
INVALID_STRING: " is not a valid string",
|
|
21
|
+
REQUIRED_DOUBLE: " is not a valid number",
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
const PARAMS = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
25
|
+
TOKEN: "token",
|
|
26
|
+
DISTINCT_ID: "distinctId",
|
|
27
|
+
ALIAS: "alias",
|
|
28
|
+
EVENT_NAME: "eventName",
|
|
29
|
+
GROUP_KEY: "groupKey",
|
|
30
|
+
PROPERTIES: "properties",
|
|
31
|
+
PROPERTY_NAME: "propertyName",
|
|
32
|
+
PROP: "prop",
|
|
33
|
+
NAME: "name",
|
|
34
|
+
CHARGE: "charge",
|
|
35
|
+
PROPERTY_VALUE: "property value",
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
const DEFAULT_OPT_OUT = false;
|
|
39
39
|
|
|
@@ -41,493 +41,528 @@ const DEFAULT_OPT_OUT = false;
|
|
|
41
41
|
* The primary class for integrating Mixpanel with your app.
|
|
42
42
|
*/
|
|
43
43
|
export class Mixpanel {
|
|
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
|
-
|
|
44
|
+
constructor(token, trackAutomaticEvents) {
|
|
45
|
+
if (!StringHelper.isValid(token)) {
|
|
46
|
+
StringHelper.raiseError(PARAMS.TOKEN);
|
|
47
|
+
}
|
|
48
|
+
if (trackAutomaticEvents == null) {
|
|
49
|
+
throw new Error(`trackAutomaticEvents is undefined`);
|
|
50
|
+
}
|
|
51
|
+
this.token = token;
|
|
52
|
+
this.trackAutomaticEvents = trackAutomaticEvents;
|
|
53
|
+
this.people = new People(this.token);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Initializes Mixpanel
|
|
58
|
+
*
|
|
59
|
+
* @param {boolean} optOutTrackingDefault Optional Whether or not Mixpanel can start tracking by default. See optOutTracking()
|
|
60
|
+
* @param {object} superProperties Optional A Map containing the key value pairs of the super properties to register
|
|
61
|
+
* @param {string} serverURL Optional Set the base URL used for Mixpanel API requests. See setServerURL()
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
async init(
|
|
65
|
+
optOutTrackingDefault = DEFAULT_OPT_OUT,
|
|
66
|
+
superProperties = {},
|
|
67
|
+
serverURL = "https://api.mixpanel.com"
|
|
68
|
+
) {
|
|
69
|
+
await MixpanelReactNative.initialize(
|
|
70
|
+
this.token,
|
|
71
|
+
this.trackAutomaticEvents,
|
|
72
|
+
optOutTrackingDefault,
|
|
73
|
+
{...Helper.getMetaData(), ...superProperties},
|
|
74
|
+
serverURL
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated since version 1.3.0. To initialize Mixpanel, please use the instance method `init` instead. See the example below:
|
|
80
|
+
*
|
|
81
|
+
* <pre><code>
|
|
82
|
+
* const trackAutomaticEvents = true;
|
|
83
|
+
* const mixpanel = new Mixpanel('your project token', trackAutomaticEvents);
|
|
84
|
+
* mixpanel.init();
|
|
85
|
+
* </code></pre>
|
|
86
|
+
*
|
|
87
|
+
* Initializes Mixpanel and return an instance of Mixpanel the given project token.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} token your project token.
|
|
90
|
+
* @param {boolean} trackAutomaticEvents Whether or not to automatically track common mobile events
|
|
91
|
+
* @param {boolean} Optional Whether or not Mixpanel can start tracking by default. See optOutTracking()
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
static async init(
|
|
95
|
+
token,
|
|
96
|
+
trackAutomaticEvents,
|
|
97
|
+
optOutTrackingDefault = DEFAULT_OPT_OUT
|
|
98
|
+
) {
|
|
99
|
+
await MixpanelReactNative.initialize(
|
|
100
|
+
token,
|
|
101
|
+
trackAutomaticEvents,
|
|
102
|
+
optOutTrackingDefault,
|
|
103
|
+
Helper.getMetaData(),
|
|
104
|
+
"https://api.mixpanel.com"
|
|
105
|
+
);
|
|
106
|
+
return new Mixpanel(token, trackAutomaticEvents);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Set the base URL used for Mixpanel API requests.
|
|
111
|
+
* Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com.
|
|
112
|
+
* To route data to Mixpanel's EU servers, set to https://api-eu.mixpanel.com
|
|
113
|
+
*
|
|
114
|
+
* @param {string} serverURL the base URL used for Mixpanel API requests
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
setServerURL(serverURL) {
|
|
118
|
+
MixpanelReactNative.setServerURL(this.token, serverURL);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* This allows enabling or disabling of all Mixpanel logs at run time.
|
|
123
|
+
* All logging is disabled by default. Usually, this is only required if
|
|
124
|
+
* you are running into issues with the SDK that you want to debug
|
|
125
|
+
*
|
|
126
|
+
* @param {boolean} loggingEnabled whether to enable logging
|
|
127
|
+
*
|
|
128
|
+
*/
|
|
129
|
+
setLoggingEnabled(loggingEnabled) {
|
|
130
|
+
MixpanelReactNative.setLoggingEnabled(this.token, loggingEnabled);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* This allows enabling or disabling whether or not Mixpanel flushes events
|
|
135
|
+
* when the app enters the background on iOS. This is set to true by default.
|
|
136
|
+
*
|
|
137
|
+
* @param {boolean} flushOnBackground whether to enable logging
|
|
138
|
+
*
|
|
139
|
+
*/
|
|
140
|
+
setFlushOnBackground(flushOnBackground) {
|
|
141
|
+
if (Platform.OS === "ios") {
|
|
142
|
+
MixpanelReactNative.setFlushOnBackground(this.token, flushOnBackground);
|
|
143
|
+
} else {
|
|
144
|
+
console.warn(
|
|
145
|
+
"Mixpanel setFlushOnBackground was called and ignored because this method only works on iOS."
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* This controls whether to automatically send the client IP Address as part of event tracking.
|
|
152
|
+
* With an IP address, geo-location is possible down to neighborhoods within a city,
|
|
153
|
+
* although the Mixpanel Dashboard will just show you city level location specificity.
|
|
154
|
+
*
|
|
155
|
+
* @param {boolean} useIpAddressForGeolocation whether to automatically send the client IP Address.
|
|
156
|
+
* Defaults to true.
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
setUseIpAddressForGeolocation(useIpAddressForGeolocation) {
|
|
160
|
+
MixpanelReactNative.setUseIpAddressForGeolocation(
|
|
161
|
+
this.token,
|
|
162
|
+
useIpAddressForGeolocation
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Set the number of events sent in a single network request to the Mixpanel server.
|
|
168
|
+
* By configuring this value, you can optimize network usage and manage the frequency of communication between the client and the server. The maximum size is 50; any value over 50 will default to 50.
|
|
169
|
+
*
|
|
170
|
+
* @param {integer} flushBatchSize whether to automatically send the client IP Address.
|
|
171
|
+
* Defaults to true.
|
|
172
|
+
*
|
|
173
|
+
*/
|
|
174
|
+
setFlushBatchSize(flushBatchSize) {
|
|
175
|
+
MixpanelReactNative.setFlushBatchSize(this.token, flushBatchSize);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Will return true if the user has opted out from tracking.
|
|
180
|
+
*
|
|
181
|
+
* @return {Promise<boolean>} true if user has opted out from tracking. Defaults to false.
|
|
182
|
+
*/
|
|
183
|
+
hasOptedOutTracking() {
|
|
184
|
+
return MixpanelReactNative.hasOptedOutTracking(this.token);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Use this method to opt-in an already opted-out user from tracking. People updates and track
|
|
189
|
+
* calls will be sent to Mixpanel after using this method.
|
|
190
|
+
* This method will internally track an opt-in event to your project.
|
|
191
|
+
*
|
|
192
|
+
*/
|
|
193
|
+
optInTracking() {
|
|
194
|
+
MixpanelReactNative.optInTracking(this.token);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Use this method to opt-out a user from tracking. Events and people updates that haven't been
|
|
199
|
+
* flushed yet will be deleted. Use flush() before calling this method if you want
|
|
200
|
+
* to send all the queues to Mixpanel before.
|
|
201
|
+
*
|
|
202
|
+
* This method will also remove any user-related information from the device.
|
|
203
|
+
*/
|
|
204
|
+
optOutTracking() {
|
|
205
|
+
MixpanelReactNative.optOutTracking(this.token);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Associate all future calls to track() with the user identified by
|
|
210
|
+
* the given distinct id.
|
|
211
|
+
*
|
|
212
|
+
* <p>Calls to track() made before corresponding calls to identify
|
|
213
|
+
* will use an anonymous locally generated distinct id, which means it is best to call identify
|
|
214
|
+
* early to ensure that your Mixpanel funnels and retention analytics can continue to track the
|
|
215
|
+
* user throughout their lifetime. We recommend calling identify when the user authenticates.
|
|
216
|
+
*
|
|
217
|
+
* <p>Once identify is called, the local distinct id persists across restarts of
|
|
218
|
+
* your application.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} distinctId a string uniquely identifying this user. Events sent to
|
|
221
|
+
* Mixpanel using the same disinct_id will be considered associated with the
|
|
222
|
+
* same visitor/customer for retention and funnel reporting, so be sure that the given
|
|
223
|
+
* value is globally unique for each individual user you intend to track.
|
|
224
|
+
* @returns {Promise} A promise that resolves when the identify is successful.
|
|
225
|
+
* It does not return any value.
|
|
226
|
+
*
|
|
227
|
+
*/
|
|
228
|
+
identify(distinctId) {
|
|
229
|
+
return new Promise((resolve, reject) => {
|
|
230
|
+
if (!StringHelper.isValid(distinctId)) {
|
|
231
|
+
StringHelper.raiseError(PARAMS.DISTINCT_ID);
|
|
232
|
+
reject(new Error("Invalid distinctId"));
|
|
233
|
+
}
|
|
234
|
+
MixpanelReactNative.identify(this.token, distinctId)
|
|
235
|
+
.then(() => {
|
|
236
|
+
resolve();
|
|
237
|
+
})
|
|
238
|
+
.catch((err) => {
|
|
239
|
+
reject(err);
|
|
220
240
|
});
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The alias method creates an alias which Mixpanel will use to remap one id to another.
|
|
246
|
+
* Multiple aliases can point to the same identifier.
|
|
247
|
+
*
|
|
248
|
+
* `mixpane.alias("New ID", mixpane.distinctId)`
|
|
249
|
+
* `mixpane.alias("Newer ID", mixpane.distinctId)`
|
|
250
|
+
*
|
|
251
|
+
* <p>This call does not identify the user after. You must still call identify()
|
|
252
|
+
* if you wish the new alias to be used for Events and People.
|
|
253
|
+
*
|
|
254
|
+
* @param {string} alias A unique identifier that you want to use as an identifier for this user.
|
|
255
|
+
* @param {string} distinctId the current distinct_id that alias will be mapped to.
|
|
256
|
+
*/
|
|
257
|
+
alias(alias, distinctId) {
|
|
258
|
+
if (!StringHelper.isValid(alias)) {
|
|
259
|
+
StringHelper.raiseError(PARAMS.ALIAS);
|
|
260
|
+
}
|
|
261
|
+
if (!StringHelper.isValid(distinctId)) {
|
|
262
|
+
StringHelper.raiseError(PARAMS.DISTINCT_ID);
|
|
263
|
+
}
|
|
264
|
+
MixpanelReactNative.alias(this.token, alias, distinctId);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Track an event.
|
|
269
|
+
*
|
|
270
|
+
* <p>Every call to track eventually results in a data point sent to Mixpanel. These data points
|
|
271
|
+
* are what are measured, counted, and broken down to create your Mixpanel reports. Events
|
|
272
|
+
* have a string name, and an optional set of name/value pairs that describe the properties of
|
|
273
|
+
* that event.
|
|
274
|
+
*
|
|
275
|
+
* @param {string} eventName The name of the event to send
|
|
276
|
+
* @param {object} properties A Map containing the key value pairs of the properties to include in this event.
|
|
277
|
+
* Pass null if no extra properties exist.
|
|
278
|
+
*/
|
|
279
|
+
track(eventName, properties) {
|
|
280
|
+
if (!StringHelper.isValid(eventName)) {
|
|
281
|
+
StringHelper.raiseError(PARAMS.EVENT_NAME);
|
|
282
|
+
}
|
|
283
|
+
if (!ObjectHelper.isValidOrUndefined(properties)) {
|
|
284
|
+
ObjectHelper.raiseError(PARAMS.PROPERTIES);
|
|
285
|
+
}
|
|
286
|
+
MixpanelReactNative.track(this.token, eventName, {
|
|
287
|
+
...Helper.getMetaData(),
|
|
288
|
+
...properties,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Returns a Mixpanel People object that can be used to set and increment
|
|
294
|
+
* People Analytics properties.
|
|
295
|
+
*
|
|
296
|
+
* @return {People} an instance of People that you can use to update
|
|
297
|
+
* records in Mixpanel People Analytics
|
|
298
|
+
*/
|
|
299
|
+
getPeople() {
|
|
300
|
+
return this.people;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Track an event with specific groups.
|
|
305
|
+
*
|
|
306
|
+
* <p>Every call to track eventually results in a data point sent to Mixpanel. These data points
|
|
307
|
+
* are what are measured, counted, and broken down to create your Mixpanel reports. Events
|
|
308
|
+
* have a string name, and an optional set of name/value pairs that describe the properties of
|
|
309
|
+
* that event. Group key/value pairs are upserted into the property map before tracking.
|
|
310
|
+
*
|
|
311
|
+
* @param {string} eventName The name of the event to send
|
|
312
|
+
* @param {object} properties A Map containing the key value pairs of the properties to include in this event.
|
|
313
|
+
* Pass null if no extra properties exist.
|
|
314
|
+
* @param {object} groups A Map containing the group key value pairs for this event.
|
|
315
|
+
*
|
|
316
|
+
*/
|
|
317
|
+
trackWithGroups(eventName, properties, groups) {
|
|
318
|
+
if (!StringHelper.isValid(eventName)) {
|
|
319
|
+
StringHelper.raiseError(PARAMS.EVENT_NAME);
|
|
320
|
+
}
|
|
321
|
+
if (!ObjectHelper.isValidOrUndefined(properties)) {
|
|
322
|
+
ObjectHelper.raiseError(PARAMS.PROPERTIES);
|
|
323
|
+
}
|
|
324
|
+
MixpanelReactNative.trackWithGroups(
|
|
325
|
+
this.token,
|
|
326
|
+
eventName,
|
|
327
|
+
{
|
|
328
|
+
...Helper.getMetaData(),
|
|
329
|
+
...properties,
|
|
330
|
+
},
|
|
331
|
+
groups
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Set the group this user belongs to.
|
|
337
|
+
*
|
|
338
|
+
* @param {string} groupKey The property name associated with this group type (must already have been set up).
|
|
339
|
+
* @param {object} groupID The group the user belongs to.
|
|
340
|
+
*/
|
|
341
|
+
setGroup(groupKey, groupID) {
|
|
342
|
+
if (!StringHelper.isValid(groupKey)) {
|
|
343
|
+
StringHelper.raiseError(PARAMS.GROUP_KEY);
|
|
344
|
+
}
|
|
345
|
+
MixpanelReactNative.setGroup(this.token, groupKey, groupID);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Returns a MixpanelGroup object that can be used to set and increment
|
|
350
|
+
* Group Analytics properties.
|
|
351
|
+
*
|
|
352
|
+
* @param {string} groupKey String identifying the type of group (must be already in use as a group key)
|
|
353
|
+
* @param {object} groupID Object identifying the specific group
|
|
354
|
+
* @return an instance of MixpanelGroup that you can use to update
|
|
355
|
+
* records in Mixpanel Group Analytics
|
|
356
|
+
*/
|
|
357
|
+
getGroup(groupKey, groupID) {
|
|
358
|
+
return new MixpanelGroup(this.token, groupKey, groupID);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Add a group to this user's membership for a particular group key
|
|
363
|
+
*
|
|
364
|
+
* @param {string} groupKey The property name associated with this group type (must already have been set up).
|
|
365
|
+
* @param {object} groupID The new group the user belongs to.
|
|
366
|
+
*/
|
|
367
|
+
addGroup(groupKey, groupID) {
|
|
368
|
+
if (!StringHelper.isValid(groupKey)) {
|
|
369
|
+
StringHelper.raiseError(PARAMS.GROUP_KEY);
|
|
370
|
+
}
|
|
371
|
+
MixpanelReactNative.addGroup(this.token, groupKey, groupID);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Remove a group from this user's membership for a particular group key
|
|
376
|
+
*
|
|
377
|
+
* @param {string} groupKey The property name associated with this group type (must already have been set up).
|
|
378
|
+
* @param {object} groupID The group value to remove.
|
|
379
|
+
*/
|
|
380
|
+
removeGroup(groupKey, groupID) {
|
|
381
|
+
if (!StringHelper.isValid(groupKey)) {
|
|
382
|
+
StringHelper.raiseError(PARAMS.GROUP_KEY);
|
|
383
|
+
}
|
|
384
|
+
MixpanelReactNative.removeGroup(this.token, groupKey, groupID);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Permanently deletes this group's record from Group Analytics.
|
|
389
|
+
*
|
|
390
|
+
* @param {string} groupKey String identifying the type of group (must be already in use as a group key)
|
|
391
|
+
* @param {object} groupID Object identifying the specific group
|
|
392
|
+
* <p>Calling deleteGroup deletes an entire record completely. Any future calls
|
|
393
|
+
* to Group Analytics using the same group value will create and store new values.
|
|
394
|
+
*/
|
|
395
|
+
deleteGroup(groupKey, groupID) {
|
|
396
|
+
if (!StringHelper.isValid(groupKey)) {
|
|
397
|
+
StringHelper.raiseError(PARAMS.GROUP_KEY);
|
|
398
|
+
}
|
|
399
|
+
MixpanelReactNative.deleteGroup(this.token, groupKey, groupID);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Register properties that will be sent with every subsequent call to track().
|
|
404
|
+
*
|
|
405
|
+
* <p>SuperProperties are a collection of properties that will be sent with every event to Mixpanel,
|
|
406
|
+
* and persist beyond the lifetime of your application.
|
|
407
|
+
*
|
|
408
|
+
* <p>Setting a superProperty with registerSuperProperties will store a new superProperty,
|
|
409
|
+
* possibly overwriting any existing superProperty with the same name (to set a
|
|
410
|
+
* superProperty only if it is currently unset, use registerSuperPropertiesOnce())
|
|
411
|
+
*
|
|
412
|
+
* <p>SuperProperties will persist even if your application is taken completely out of memory.
|
|
413
|
+
* to remove a superProperty, call unregisterSuperProperty() or clearSuperProperties()
|
|
414
|
+
*
|
|
415
|
+
* @param {object} properties A Map containing super properties to register
|
|
416
|
+
*/
|
|
417
|
+
registerSuperProperties(properties) {
|
|
418
|
+
if (!ObjectHelper.isValidOrUndefined(properties)) {
|
|
419
|
+
ObjectHelper.raiseError(PARAMS.PROPERTIES);
|
|
420
|
+
}
|
|
421
|
+
MixpanelReactNative.registerSuperProperties(this.token, properties || {});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Register super properties for events, only if no other super property with the
|
|
426
|
+
* same names has already been registered.
|
|
427
|
+
*
|
|
428
|
+
* <p>Calling registerSuperPropertiesOnce will never overwrite existing properties.
|
|
429
|
+
*
|
|
430
|
+
* @param {object} properties A Map containing the super properties to register.
|
|
431
|
+
*/
|
|
432
|
+
registerSuperPropertiesOnce(properties) {
|
|
433
|
+
if (!ObjectHelper.isValidOrUndefined(properties)) {
|
|
434
|
+
ObjectHelper.raiseError(PARAMS.PROPERTIES);
|
|
435
|
+
}
|
|
436
|
+
MixpanelReactNative.registerSuperPropertiesOnce(
|
|
437
|
+
this.token,
|
|
438
|
+
properties || {}
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Remove a single superProperty, so that it will not be sent with future calls to track().
|
|
444
|
+
*
|
|
445
|
+
* <p>If there is a superProperty registered with the given name, it will be permanently
|
|
446
|
+
* removed from the existing superProperties.
|
|
447
|
+
* To clear all superProperties, use clearSuperProperties()
|
|
448
|
+
*
|
|
449
|
+
* @param {string} propertyName name of the property to unregister
|
|
450
|
+
*/
|
|
451
|
+
unregisterSuperProperty(propertyName) {
|
|
452
|
+
if (!StringHelper.isValid(propertyName)) {
|
|
453
|
+
StringHelper.raiseError(PARAMS.PROPERTY_NAME);
|
|
454
|
+
}
|
|
455
|
+
MixpanelReactNative.unregisterSuperProperty(this.token, propertyName);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Returns a json object of the user's current super properties
|
|
460
|
+
*
|
|
461
|
+
*<p>SuperProperties are a collection of properties that will be sent with every event to Mixpanel,
|
|
462
|
+
* and persist beyond the lifetime of your application.
|
|
463
|
+
*
|
|
464
|
+
* @return {Promise<object>} Super properties for this Mixpanel instance.
|
|
465
|
+
*/
|
|
466
|
+
getSuperProperties() {
|
|
467
|
+
return MixpanelReactNative.getSuperProperties(this.token);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Erase all currently registered superProperties.
|
|
472
|
+
*
|
|
473
|
+
* <p>Future tracking calls to Mixpanel will not contain the specific
|
|
474
|
+
* superProperties registered before the clearSuperProperties method was called.
|
|
475
|
+
*
|
|
476
|
+
* <p>To remove a single superProperty, use unregisterSuperProperty()
|
|
477
|
+
*/
|
|
478
|
+
clearSuperProperties() {
|
|
479
|
+
MixpanelReactNative.clearSuperProperties(this.token);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Begin timing of an event. Calling timeEvent("Thing") will not send an event, but
|
|
484
|
+
* when you eventually call track("Thing"), your tracked event will be sent with a "$duration"
|
|
485
|
+
* property, representing the number of seconds between your calls.
|
|
486
|
+
*
|
|
487
|
+
* @param {string} eventName the name of the event to track with timing.
|
|
488
|
+
*/
|
|
489
|
+
timeEvent(eventName) {
|
|
490
|
+
if (!StringHelper.isValid(eventName)) {
|
|
491
|
+
StringHelper.raiseError(PARAMS.EVENT_NAME);
|
|
492
|
+
}
|
|
493
|
+
MixpanelReactNative.timeEvent(this.token, eventName);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Retrieves the time elapsed for the named event since timeEvent() was called.
|
|
498
|
+
*
|
|
499
|
+
* @param {string} eventName the name of the event to be tracked that was previously called with timeEvent()
|
|
500
|
+
*
|
|
501
|
+
* @return {Promise<number>} Time elapsed since timeEvent(String) was called for the given eventName.
|
|
502
|
+
*/
|
|
503
|
+
eventElapsedTime(eventName) {
|
|
504
|
+
if (!StringHelper.isValid(eventName)) {
|
|
505
|
+
StringHelper.raiseError(PARAMS.EVENT_NAME);
|
|
506
|
+
}
|
|
507
|
+
return MixpanelReactNative.eventElapsedTime(this.token, eventName);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
476
511
|
Clear super properties and generates a new random distinctId for this instance.
|
|
477
512
|
Useful for clearing data when a user logs out.
|
|
478
513
|
*/
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
514
|
+
reset() {
|
|
515
|
+
MixpanelReactNative.reset(this.token);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Returns the current distinct id of the user.
|
|
520
|
+
* This is either the id automatically generated by the library or the id that has been passed by a call to identify().
|
|
521
|
+
*
|
|
522
|
+
* example of usage:
|
|
523
|
+
* <pre>
|
|
524
|
+
* <code>
|
|
525
|
+
* const distinctId = await mixpanel.getDistinctId();
|
|
526
|
+
* </code>
|
|
527
|
+
* </pre>
|
|
528
|
+
*
|
|
529
|
+
* @return {Promise<string>} A Promise to the distinct id associated with Mixpanel event and People Analytics
|
|
530
|
+
*
|
|
531
|
+
*/
|
|
532
|
+
getDistinctId() {
|
|
533
|
+
return MixpanelReactNative.getDistinctId(this.token);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Returns the current device id of the device.
|
|
538
|
+
* This id automatically generated by the library and regenerated when logout or reset is called.
|
|
539
|
+
*
|
|
540
|
+
* example of usage:
|
|
541
|
+
* <pre>
|
|
542
|
+
* <code>
|
|
543
|
+
* const deviceId = await mixpanel.getDeviceId();
|
|
544
|
+
* </code>
|
|
545
|
+
* </pre>
|
|
546
|
+
*
|
|
547
|
+
* @return {Promise<string>} A Promise to the device id
|
|
548
|
+
*
|
|
549
|
+
*/
|
|
550
|
+
getDeviceId() {
|
|
551
|
+
return MixpanelReactNative.getDeviceId(this.token);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Push all queued Mixpanel events and People Analytics changes to Mixpanel servers.
|
|
556
|
+
*
|
|
557
|
+
* <p>Events and People messages are pushed gradually throughout
|
|
558
|
+
* the lifetime of your application. This means that to ensure that all messages
|
|
559
|
+
* are sent to Mixpanel when your application is shut down, you will
|
|
560
|
+
* need to call flush() to let the Mixpanel library know it should
|
|
561
|
+
* send all remaining messages to the server.
|
|
562
|
+
*/
|
|
563
|
+
flush() {
|
|
564
|
+
MixpanelReactNative.flush(this.token);
|
|
565
|
+
}
|
|
531
566
|
}
|
|
532
567
|
|
|
533
568
|
/**
|
|
@@ -542,199 +577,202 @@ export class Mixpanel {
|
|
|
542
577
|
*
|
|
543
578
|
*/
|
|
544
579
|
export class People {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
580
|
+
constructor(token) {
|
|
581
|
+
if (!StringHelper.isValid(token)) {
|
|
582
|
+
StringHelper.raiseError(PARAMS.TOKEN);
|
|
583
|
+
}
|
|
584
|
+
this.token = token;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Sets a single property with the given name and value for this user.
|
|
589
|
+
* The given name and value will be assigned to the user in Mixpanel People Analytics,
|
|
590
|
+
* possibly overwriting an existing property with the same name.
|
|
591
|
+
*
|
|
592
|
+
* @param {string} prop The name of the Mixpanel property. This must be a String, for example "Zip Code"
|
|
593
|
+
* @param {object} to The value of the Mixpanel property. For "Zip Code", this value might be the String "90210"
|
|
594
|
+
*/
|
|
595
|
+
set(prop, to) {
|
|
596
|
+
let properties = {};
|
|
597
|
+
if (ObjectHelper.isValid(prop)) {
|
|
598
|
+
properties = JSON.parse(JSON.stringify(prop || {}));
|
|
599
|
+
} else {
|
|
600
|
+
if (!StringHelper.isValid(prop)) {
|
|
601
|
+
StringHelper.raiseError(PARAMS.PROP);
|
|
602
|
+
}
|
|
603
|
+
properties[prop] = to;
|
|
604
|
+
}
|
|
605
|
+
MixpanelReactNative.set(this.token, properties);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Works just like set(), except it will not overwrite existing property values. This is useful for properties like "First login date".
|
|
610
|
+
*
|
|
611
|
+
* @param {string} prop The name of the Mixpanel property. This must be a String, for example "Zip Code"
|
|
612
|
+
* @param {object} to The value of the Mixpanel property. For "Zip Code", this value might be the String "90210"
|
|
613
|
+
*/
|
|
614
|
+
setOnce(prop, to) {
|
|
615
|
+
let properties = {};
|
|
616
|
+
if (ObjectHelper.isValid(prop)) {
|
|
617
|
+
prop = prop || {};
|
|
618
|
+
properties = JSON.parse(JSON.stringify(prop));
|
|
619
|
+
} else {
|
|
620
|
+
if (!StringHelper.isValid(prop)) {
|
|
621
|
+
StringHelper.raiseError(PARAMS.PROP);
|
|
622
|
+
}
|
|
623
|
+
properties[prop] = to;
|
|
624
|
+
}
|
|
625
|
+
MixpanelReactNative.setOnce(this.token, properties);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Add the given amount to an existing property on the identified user. If the user does not already
|
|
630
|
+
* have the associated property, the amount will be added to zero. To reduce a property,
|
|
631
|
+
* provide a negative number for the value.
|
|
632
|
+
*
|
|
633
|
+
* @param {string} prop the People Analytics property that should have its value changed
|
|
634
|
+
* @param {number} by the amount to be added to the current value of the named property
|
|
635
|
+
*
|
|
636
|
+
*/
|
|
637
|
+
increment(prop, by) {
|
|
638
|
+
var add = {};
|
|
639
|
+
if (ObjectHelper.isValid(prop)) {
|
|
640
|
+
Object.keys(prop).forEach(function (key) {
|
|
641
|
+
var val = prop[key];
|
|
642
|
+
if (isNaN(parseFloat(val))) {
|
|
643
|
+
throw new Error(
|
|
644
|
+
`${PARAMS.PROPERTY_VALUE}${ERROR_MESSAGE.REQUIRED_DOUBLE}`
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
add[key] = val;
|
|
648
|
+
});
|
|
649
|
+
} else {
|
|
650
|
+
by = by || 1;
|
|
651
|
+
if (isNaN(parseFloat(by))) {
|
|
652
|
+
throw new Error(
|
|
653
|
+
`${PARAMS.PROPERTY_VALUE}${ERROR_MESSAGE.REQUIRED_DOUBLE}`
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (!StringHelper.isValid(prop)) {
|
|
658
|
+
StringHelper.raiseError(PARAMS.NAME);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
add[prop] = by;
|
|
662
|
+
}
|
|
663
|
+
MixpanelReactNative.increment(this.token, add);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Appends a value to a list-valued property. If the property does not currently exist,
|
|
668
|
+
* it will be created as a list of one element. If the property does exist and doesn't
|
|
669
|
+
* currently have a list value, the append will be ignored.
|
|
670
|
+
* @param {string} name the People Analytics property that should have it's value appended to
|
|
671
|
+
* @param {object} value the new value that will appear at the end of the property's list
|
|
672
|
+
*/
|
|
673
|
+
append(name, value) {
|
|
674
|
+
let appendProp = {};
|
|
675
|
+
if (!StringHelper.isValid(name)) {
|
|
676
|
+
StringHelper.raiseError(PARAMS.NAME);
|
|
677
|
+
} else {
|
|
678
|
+
appendProp[name] = value;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (DevicePlatform.iOS === Helper.getDevicePlatform()) {
|
|
682
|
+
MixpanelReactNative.append(this.token, appendProp);
|
|
683
|
+
} else {
|
|
684
|
+
MixpanelReactNative.append(this.token, name, value);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Adds values to a list-valued property only if they are not already present in the list.
|
|
690
|
+
* If the property does not currently exist, it will be created with the given list as it's value.
|
|
691
|
+
* If the property exists and is not list-valued, the union will be ignored.
|
|
692
|
+
*
|
|
693
|
+
* @param {string} name name of the list-valued property to set or modify
|
|
694
|
+
* @param {array} value an array of values to add to the property value if not already present
|
|
695
|
+
*/
|
|
696
|
+
union(name, value) {
|
|
697
|
+
if (!StringHelper.isValid(name)) {
|
|
698
|
+
StringHelper.raiseError(PARAMS.NAME);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
value = Array.isArray(value) ? value : [value];
|
|
702
|
+
|
|
703
|
+
if (DevicePlatform.iOS === Helper.getDevicePlatform()) {
|
|
704
|
+
MixpanelReactNative.union(this.token, {[name]: value});
|
|
705
|
+
} else {
|
|
706
|
+
MixpanelReactNative.union(this.token, name, value);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Remove value from a list-valued property only if they are already present in the list.
|
|
712
|
+
* If the property does not currently exist, the remove will be ignored.
|
|
713
|
+
* If the property exists and is not list-valued, the remove will be ignored.
|
|
714
|
+
* @param {string} name the People Analytics property that should have it's value removed from
|
|
715
|
+
* @param {object} value the value that will be removed from the property's list
|
|
716
|
+
*/
|
|
717
|
+
remove(name, value) {
|
|
718
|
+
let removeProp = {};
|
|
719
|
+
if (!StringHelper.isValid(name)) {
|
|
720
|
+
StringHelper.raiseError(PARAMS.NAME);
|
|
721
|
+
} else {
|
|
722
|
+
removeProp[name] = value;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
if (DevicePlatform.iOS === Helper.getDevicePlatform()) {
|
|
726
|
+
MixpanelReactNative.remove(this.token, removeProp);
|
|
727
|
+
} else {
|
|
728
|
+
MixpanelReactNative.remove(this.token, name, value);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* permanently removes the property with the given name from the user's profile
|
|
734
|
+
* @param {string} name name of a property to unset
|
|
735
|
+
*/
|
|
736
|
+
unset(name) {
|
|
737
|
+
if (!StringHelper.isValid(name)) {
|
|
738
|
+
StringHelper.raiseError(PARAMS.PROPERTY_NAME);
|
|
739
|
+
}
|
|
740
|
+
MixpanelReactNative.unset(this.token, name);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Track a revenue transaction for the identified people profile.
|
|
745
|
+
*
|
|
746
|
+
* @param {number} charge the amount of money exchanged. Positive amounts represent purchases or income from the customer, negative amounts represent refunds or payments to the customer.
|
|
747
|
+
* @param {object} properties an optional collection of properties to associate with this transaction.
|
|
748
|
+
*/
|
|
749
|
+
trackCharge(charge, properties) {
|
|
750
|
+
if (isNaN(parseFloat(charge))) {
|
|
751
|
+
throw new Error(`${PARAMS.CHARGE}${ERROR_MESSAGE.REQUIRED_DOUBLE}`);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (!ObjectHelper.isValidOrUndefined(properties)) {
|
|
755
|
+
ObjectHelper.raiseError(PARAMS.PROPERTIES);
|
|
756
|
+
}
|
|
757
|
+
MixpanelReactNative.trackCharge(this.token, charge, properties || {});
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Permanently clear the whole transaction history for the identified people profile.
|
|
762
|
+
*/
|
|
763
|
+
clearCharges() {
|
|
764
|
+
MixpanelReactNative.clearCharges(this.token);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Permanently deletes the identified user's record from People Analytics.
|
|
769
|
+
*
|
|
770
|
+
* <p>Calling deleteUser deletes an entire record completely. Any future calls
|
|
771
|
+
* to People Analytics using the same distinct id will create and store new values.
|
|
772
|
+
*/
|
|
773
|
+
deleteUser() {
|
|
774
|
+
MixpanelReactNative.deleteUser(this.token);
|
|
775
|
+
}
|
|
738
776
|
}
|
|
739
777
|
|
|
740
778
|
/**
|
|
@@ -743,169 +781,194 @@ export class People {
|
|
|
743
781
|
* <p>The MixpanelGroup object is used to update properties in a group's Group Analytics record.
|
|
744
782
|
*/
|
|
745
783
|
export class MixpanelGroup {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
784
|
+
constructor(token, groupKey, groupID) {
|
|
785
|
+
if (!StringHelper.isValid(token)) {
|
|
786
|
+
StringHelper.raiseError(PARAMS.TOKEN);
|
|
787
|
+
}
|
|
788
|
+
this.token = token;
|
|
789
|
+
this.groupKey = groupKey;
|
|
790
|
+
this.groupID = groupID;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Sets a single property with the given name and value for this group.
|
|
795
|
+
* The given name and value will be assigned to the user in Mixpanel Group Analytics,
|
|
796
|
+
* possibly overwriting an existing property with the same name.
|
|
797
|
+
*
|
|
798
|
+
* @param {string} prop The name of the Mixpanel property. This must be a String, for example "Zip Code"
|
|
799
|
+
* @param {string} to The value to set on the given property name. For "Zip Code", this value might be the String "90210"
|
|
800
|
+
*/
|
|
801
|
+
set(prop, to) {
|
|
802
|
+
let properties = {};
|
|
803
|
+
if (ObjectHelper.isValid(prop)) {
|
|
804
|
+
properties = JSON.parse(JSON.stringify(prop || {}));
|
|
805
|
+
} else {
|
|
806
|
+
if (!StringHelper.isValid(prop)) {
|
|
807
|
+
StringHelper.raiseError(PARAMS.PROP);
|
|
808
|
+
}
|
|
809
|
+
properties[prop] = to;
|
|
810
|
+
}
|
|
811
|
+
MixpanelReactNative.groupSetProperties(
|
|
812
|
+
this.token,
|
|
813
|
+
this.groupKey,
|
|
814
|
+
this.groupID,
|
|
815
|
+
properties
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Works just like groupSet() except it will not overwrite existing property values. This is useful for properties like "First login date".
|
|
821
|
+
*
|
|
822
|
+
* @param {string} prop The name of the Mixpanel property. This must be a String, for example "Zip Code"
|
|
823
|
+
* @param {string} to The value to set on the given property name. For "Zip Code", this value might be the String "90210"
|
|
824
|
+
*/
|
|
825
|
+
setOnce(prop, to) {
|
|
826
|
+
let properties = {};
|
|
827
|
+
if (ObjectHelper.isValid(prop)) {
|
|
828
|
+
properties = JSON.parse(JSON.stringify(prop || {}));
|
|
829
|
+
} else {
|
|
830
|
+
if (!StringHelper.isValid(prop)) {
|
|
831
|
+
StringHelper.raiseError(PARAMS.PROP);
|
|
832
|
+
}
|
|
833
|
+
properties[prop] = to;
|
|
834
|
+
}
|
|
835
|
+
MixpanelReactNative.groupSetPropertyOnce(
|
|
836
|
+
this.token,
|
|
837
|
+
this.groupKey,
|
|
838
|
+
this.groupID,
|
|
839
|
+
properties
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Permanently removes the property with the given name from the group's profile
|
|
845
|
+
*
|
|
846
|
+
* @param {string} prop name of a property to unset
|
|
847
|
+
*/
|
|
848
|
+
unset(prop) {
|
|
849
|
+
if (!StringHelper.isValid(prop)) {
|
|
850
|
+
StringHelper.raiseError(PARAMS.PROPERTY_NAME);
|
|
851
|
+
}
|
|
852
|
+
MixpanelReactNative.groupUnsetProperty(
|
|
853
|
+
this.token,
|
|
854
|
+
this.groupKey,
|
|
855
|
+
this.groupID,
|
|
856
|
+
prop
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Remove value from a list-valued property only if it is already present in the list.
|
|
862
|
+
* If the property does not currently exist, the remove will be ignored.
|
|
863
|
+
* If the property exists and is not list-valued, the remove will be ignored.
|
|
864
|
+
*
|
|
865
|
+
* @param {string} name the Group Analytics list-valued property that should have a value removed
|
|
866
|
+
* @param {any} value the value that will be removed from the list
|
|
867
|
+
*/
|
|
868
|
+
remove(name, value) {
|
|
869
|
+
if (!StringHelper.isValid(name)) {
|
|
870
|
+
StringHelper.raiseError(PARAMS.PROPERTY_NAME);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
MixpanelReactNative.groupRemovePropertyValue(
|
|
874
|
+
this.token,
|
|
875
|
+
this.groupKey,
|
|
876
|
+
this.groupID,
|
|
877
|
+
name,
|
|
878
|
+
value
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Adds values to a list-valued property only if they are not already present in the list.
|
|
884
|
+
* If the property does not currently exist, it will be created with the given list as its value.
|
|
885
|
+
* If the property exists and is not list-valued, the union will be ignored.
|
|
886
|
+
*
|
|
887
|
+
* @param {string} name name of the list-valued property to set or modify
|
|
888
|
+
* @param {array} value an array of values to add to the property value if not already present
|
|
889
|
+
*/
|
|
890
|
+
union(name, value) {
|
|
891
|
+
if (!StringHelper.isValid(name)) {
|
|
892
|
+
StringHelper.raiseError(PARAMS.PROPERTY_NAME);
|
|
893
|
+
}
|
|
894
|
+
value = Array.isArray(value) ? value : [value];
|
|
895
|
+
MixpanelReactNative.groupUnionProperty(
|
|
896
|
+
this.token,
|
|
897
|
+
this.groupKey,
|
|
898
|
+
this.groupID,
|
|
899
|
+
name,
|
|
900
|
+
value
|
|
901
|
+
);
|
|
902
|
+
}
|
|
840
903
|
}
|
|
841
904
|
|
|
842
905
|
class Helper {
|
|
843
|
-
|
|
906
|
+
/**
|
|
844
907
|
Get the library data from package.json file.
|
|
845
908
|
*/
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
909
|
+
static getMetaData() {
|
|
910
|
+
let metadata = JSON.parse(JSON.stringify(packageJson.metadata));
|
|
911
|
+
metadata["$lib_version"] = packageJson.version;
|
|
912
|
+
return metadata;
|
|
913
|
+
}
|
|
851
914
|
|
|
852
|
-
|
|
915
|
+
/**
|
|
853
916
|
Get current device platform.
|
|
854
917
|
*/
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
}
|
|
918
|
+
static getDevicePlatform() {
|
|
919
|
+
switch (Platform.OS) {
|
|
920
|
+
case "android":
|
|
921
|
+
return DevicePlatform.Android;
|
|
922
|
+
case "ios":
|
|
923
|
+
return DevicePlatform.iOS;
|
|
924
|
+
default:
|
|
925
|
+
return DevicePlatform.Unknown;
|
|
864
926
|
}
|
|
927
|
+
}
|
|
865
928
|
}
|
|
866
929
|
|
|
867
930
|
class StringHelper {
|
|
868
|
-
|
|
931
|
+
/**
|
|
869
932
|
Check whether the parameter is not a blank string.
|
|
870
933
|
*/
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
934
|
+
static isValid(str) {
|
|
935
|
+
return typeof str === "string" && !/^\s*$/.test(str);
|
|
936
|
+
}
|
|
874
937
|
|
|
875
|
-
|
|
938
|
+
/**
|
|
876
939
|
Check whether the parameter is undefined or not a blank string.
|
|
877
940
|
*/
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
941
|
+
static isValidOrUndefined(str) {
|
|
942
|
+
return str === undefined || StringHelper.isValid(str);
|
|
943
|
+
}
|
|
881
944
|
|
|
882
|
-
|
|
945
|
+
/**
|
|
883
946
|
Raise a string validation error.
|
|
884
947
|
*/
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
948
|
+
static raiseError(paramName) {
|
|
949
|
+
throw new Error(`${paramName}${ERROR_MESSAGE.INVALID_STRING}`);
|
|
950
|
+
}
|
|
888
951
|
}
|
|
889
952
|
|
|
890
953
|
class ObjectHelper {
|
|
891
|
-
|
|
954
|
+
/**
|
|
892
955
|
Check whether the parameter is an object.
|
|
893
956
|
*/
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
957
|
+
static isValid(obj) {
|
|
958
|
+
return typeof obj === "object";
|
|
959
|
+
}
|
|
897
960
|
|
|
898
|
-
|
|
961
|
+
/**
|
|
899
962
|
Check whether the parameter is undefined or an object.
|
|
900
963
|
*/
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
964
|
+
static isValidOrUndefined(obj) {
|
|
965
|
+
return obj === undefined || ObjectHelper.isValid(obj);
|
|
966
|
+
}
|
|
904
967
|
|
|
905
|
-
|
|
968
|
+
/**
|
|
906
969
|
Raise an object validation error.
|
|
907
970
|
*/
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
971
|
+
static raiseError(paramName) {
|
|
972
|
+
throw new Error(`${paramName}${ERROR_MESSAGE.INVALID_OBJECT}`);
|
|
973
|
+
}
|
|
911
974
|
}
|