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