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