mixpanel-react-native 2.2.4 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  #
2
2
 
3
+ ## [v2.3.0](https://github.com/mixpanel/mixpanel-react-native/tree/v2.3.0) (2023-06-16)
4
+
5
+ ### Enhancements
6
+
7
+ - Returning Promise for the identify\(\) to avoid race condition [\#200](https://github.com/mixpanel/mixpanel-react-native/pull/200)
8
+
9
+ ### Fixes
10
+
11
+ - Fix null reference used for synchronization \(monitor-enter\) [\#199](https://github.com/mixpanel/mixpanel-react-native/pull/199)
12
+ - fix initialize was called with 4 arguments but expects 5 arguments [\#198](https://github.com/mixpanel/mixpanel-react-native/pull/198)
13
+ - safer handling of super properties [\#197](https://github.com/mixpanel/mixpanel-react-native/pull/197)
14
+ - Android resource linking failure fix [\#187](https://github.com/mixpanel/mixpanel-react-native/pull/187)
15
+
16
+ **Closed issues:**
17
+
18
+ - Support new React Native new architecture \(TurboModules/Fabric\) [\#145](https://github.com/mixpanel/mixpanel-react-native/issues/145)
19
+ - Feature Request: Built in getInstance\(\) or similar instead of custom tooling [\#139](https://github.com/mixpanel/mixpanel-react-native/issues/139)
20
+ - \[Feature Request\] Add support for Expo Config Plugins [\#69](https://github.com/mixpanel/mixpanel-react-native/issues/69)
21
+
22
+ #
23
+
24
+ ## [v2.2.5](https://github.com/mixpanel/mixpanel-react-native/tree/v2.2.5) (2023-04-29)
25
+
26
+ ### Fixes
27
+
28
+ - Remove semaphores, copy properties, use .merging, don't includeLibInfo in init [\#191](https://github.com/mixpanel/mixpanel-react-native/pull/191)
29
+
30
+ #
31
+
3
32
  ## [v2.2.4](https://github.com/mixpanel/mixpanel-react-native/tree/v2.2.4) (2023-04-25)
4
33
 
5
34
  ### Fixes
@@ -288,6 +317,10 @@ Report issues or give us any feedback is appreciated!
288
317
 
289
318
 
290
319
 
320
+
321
+
322
+
323
+
291
324
 
292
325
 
293
326
 
@@ -19,5 +19,5 @@ Pod::Spec.new do |s|
19
19
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
20
20
 
21
21
  s.dependency "React-Core"
22
- s.dependency "Mixpanel-swift", '4.1.0'
22
+ s.dependency "Mixpanel-swift", '4.1.3'
23
23
  end
package/README.md CHANGED
@@ -100,7 +100,7 @@ const SampleApp = () => {
100
100
  export default SampleApp;
101
101
 
102
102
  ```
103
-
103
+ ### For Expo support, please refer to this [issue](https://github.com/mixpanel/mixpanel-react-native/issues/82)
104
104
  👋 👋 Tell us about the Mixpanel developer experience! [https://www.mixpanel.com/devnps](https://www.mixpanel.com/devnps) 👍 👎
105
105
 
106
106
 
@@ -112,7 +112,7 @@ Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpa
112
112
  Mixpanel’s client-side tracking library contains the [optOutTracking()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#optOutTracking) method, which will set the user’s local opt-out state to “true” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section, [Opting users out of tracking](https://developer.mixpanel.com/docs/react-native#opting-users-out-of-tracking).
113
113
 
114
114
  **Why aren't my events showing up?**
115
- To preserve battery life and customer bandwidth, the Mixpanel library doesn't send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call [flush()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#flush) manually if you want to force a flush at a particular moment.
115
+ First, make sure your test device has internet access. To preserve battery life and customer bandwidth, the Mixpanel library doesn't send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call [flush()](https://mixpanel.github.io/mixpanel-react-native/Mixpanel.html#flush) manually if you want to force a flush at a particular moment.
116
116
 
117
117
  ```
118
118
  mixpanel.flush();
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>android_</name>
4
+ <comment>Project android_ created by Buildship.</comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16
+ </natures>
17
+ <filteredResources>
18
+ <filter>
19
+ <id>1686200212448</id>
20
+ <name></name>
21
+ <type>30</type>
22
+ <matcher>
23
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
24
+ <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25
+ </matcher>
26
+ </filter>
27
+ </filteredResources>
28
+ </projectDescription>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>android__</name>
4
+ <comment>Project android__ created by Buildship.</comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16
+ </natures>
17
+ <filteredResources>
18
+ <filter>
19
+ <id>1686200212452</id>
20
+ <name></name>
21
+ <type>30</type>
22
+ <matcher>
23
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
24
+ <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25
+ </matcher>
26
+ </filter>
27
+ </filteredResources>
28
+ </projectDescription>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>SimpleMixpanel</name>
4
+ <comment>Project android created by Buildship.</comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16
+ </natures>
17
+ <filteredResources>
18
+ <filter>
19
+ <id>1686200212442</id>
20
+ <name></name>
21
+ <type>30</type>
22
+ <matcher>
23
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
24
+ <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25
+ </matcher>
26
+ </filter>
27
+ </filteredResources>
28
+ </projectDescription>
@@ -9,13 +9,13 @@ import { NativeModules } from 'react-native';
9
9
 
10
10
  test(`it calls MixpanelReactNative initialize`, async () => {
11
11
  const mixpanel = await Mixpanel.init("token", true);
12
- expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, false, {"$lib_version": "2.2.4", "mp_lib": "react-native"});
12
+ expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, false, {"$lib_version": "2.3.0", "mp_lib": "react-native"}, "https://api.mixpanel.com");
13
13
  });
14
14
 
15
15
  test(`it calls MixpanelReactNative initialize with optOut and superProperties`, async () => {
16
16
  const mixpanel = new Mixpanel("token", true);
17
17
  mixpanel.init(true, {"super": "property"})
18
- expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, true, {"$lib_version": "2.2.4", "mp_lib": "react-native", "super": "property"}, "https://api.mixpanel.com");
18
+ expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, true, {"$lib_version": "2.3.0", "mp_lib": "react-native", "super": "property"}, "https://api.mixpanel.com");
19
19
  });
20
20
 
21
21
  test(`it calls MixpanelReactNative setServerURL`, async () => {
@@ -4,18 +4,18 @@ buildscript {
4
4
  google()
5
5
  }
6
6
  dependencies {
7
- classpath 'com.android.tools.build:gradle:3.4.1'
7
+ classpath 'com.android.tools.build:gradle:7.3.1'
8
8
  }
9
9
  }
10
10
 
11
11
  apply plugin: 'com.android.library'
12
12
 
13
13
  android {
14
- compileSdkVersion 30
14
+ compileSdkVersion 33
15
15
  buildToolsVersion "30.0.3"
16
16
  defaultConfig {
17
17
  minSdkVersion 21
18
- targetSdkVersion 30
18
+ targetSdkVersion 33
19
19
  versionCode 1
20
20
  versionName "1.0"
21
21
  }
@@ -34,5 +34,5 @@ repositories {
34
34
 
35
35
  dependencies {
36
36
  implementation 'com.facebook.react:react-native:+'
37
- implementation 'com.mixpanel.android:mixpanel-android:7.3.0'
37
+ implementation 'com.mixpanel.android:mixpanel-android:7.3.1'
38
38
  }
@@ -44,6 +44,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
44
44
  @ReactMethod
45
45
  public void setServerURL(final String token, final String serverURL, Promise promise) throws JSONException {
46
46
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
47
+ if (instance == null) {
48
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
49
+ return;
50
+ }
47
51
  synchronized (instance) {
48
52
  instance.setServerURL(serverURL);
49
53
  promise.resolve(null);
@@ -53,6 +57,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
53
57
  @ReactMethod
54
58
  public void setUseIpAddressForGeolocation(final String token, boolean useIpAddressForGeolocation, Promise promise) throws JSONException {
55
59
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
60
+ if (instance == null) {
61
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
62
+ return;
63
+ }
56
64
  synchronized (instance) {
57
65
  instance.setUseIpAddressForGeolocation(useIpAddressForGeolocation);
58
66
  promise.resolve(null);
@@ -62,6 +70,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
62
70
  @ReactMethod
63
71
  public void setLoggingEnabled(final String token, boolean enableLogging, Promise promise) throws JSONException {
64
72
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
73
+ if (instance == null) {
74
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
75
+ return;
76
+ }
65
77
  synchronized (instance) {
66
78
  instance.setEnableLogging(enableLogging);
67
79
  promise.resolve(null);
@@ -71,6 +83,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
71
83
  @ReactMethod
72
84
  public void hasOptedOutTracking(final String token, Promise promise) {
73
85
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
86
+ if (instance == null) {
87
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
88
+ return;
89
+ }
74
90
  synchronized (instance) {
75
91
  promise.resolve(instance.hasOptedOutTracking());
76
92
  }
@@ -79,6 +95,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
79
95
  @ReactMethod
80
96
  public void optInTracking(final String token, Promise promise) throws JSONException {
81
97
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
98
+ if (instance == null) {
99
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
100
+ return;
101
+ }
82
102
  synchronized (instance) {
83
103
  instance.optInTracking();
84
104
  promise.resolve(null);
@@ -88,6 +108,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
88
108
  @ReactMethod
89
109
  public void optOutTracking(final String token, Promise promise) {
90
110
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
111
+ if (instance == null) {
112
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
113
+ return;
114
+ }
91
115
  synchronized (instance) {
92
116
  instance.optOutTracking();
93
117
  promise.resolve(null);
@@ -97,6 +121,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
97
121
  @ReactMethod
98
122
  public void identify(final String token, final String distinctId, Promise promise) {
99
123
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
124
+ if (instance == null) {
125
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
126
+ return;
127
+ }
100
128
  synchronized (instance) {
101
129
  instance.identify(distinctId);
102
130
  promise.resolve(null);
@@ -106,6 +134,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
106
134
  @ReactMethod
107
135
  public void getDistinctId(final String token, Promise promise) {
108
136
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
137
+ if (instance == null) {
138
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
139
+ return;
140
+ }
109
141
  synchronized (instance) {
110
142
  promise.resolve(instance.getDistinctId());
111
143
  }
@@ -114,6 +146,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
114
146
  @ReactMethod
115
147
  public void getDeviceId(final String token, Promise promise) {
116
148
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
149
+ if (instance == null) {
150
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
151
+ return;
152
+ }
117
153
  synchronized (instance) {
118
154
  promise.resolve(instance.getAnonymousId());
119
155
  }
@@ -122,6 +158,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
122
158
  @ReactMethod
123
159
  public void track(final String token, final String eventName, ReadableMap properties, Promise promise) throws JSONException {
124
160
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
161
+ if (instance == null) {
162
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
163
+ return;
164
+ }
125
165
  synchronized (instance) {
126
166
  JSONObject eventProperties = ReactNativeHelper.reactToJSON(properties);
127
167
  AutomaticProperties.appendLibraryProperties(eventProperties);
@@ -133,6 +173,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
133
173
  @ReactMethod
134
174
  public void registerSuperProperties(final String token, ReadableMap properties, Promise promise) throws JSONException {
135
175
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
176
+ if (instance == null) {
177
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
178
+ return;
179
+ }
136
180
  synchronized (instance) {
137
181
  JSONObject superProperties = ReactNativeHelper.reactToJSON(properties);
138
182
  instance.registerSuperProperties(superProperties);
@@ -143,6 +187,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
143
187
  @ReactMethod
144
188
  public void registerSuperPropertiesOnce(final String token, ReadableMap properties, Promise promise) throws JSONException {
145
189
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
190
+ if (instance == null) {
191
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
192
+ return;
193
+ }
146
194
  synchronized (instance) {
147
195
  JSONObject superProperties = ReactNativeHelper.reactToJSON(properties);
148
196
  instance.registerSuperPropertiesOnce(superProperties);
@@ -153,6 +201,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
153
201
  @ReactMethod
154
202
  public void unregisterSuperProperty(final String token, String superPropertyName, Promise promise) {
155
203
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
204
+ if (instance == null) {
205
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
206
+ return;
207
+ }
156
208
  synchronized (instance) {
157
209
  instance.unregisterSuperProperty(superPropertyName);
158
210
  promise.resolve(null);
@@ -162,6 +214,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
162
214
  @ReactMethod
163
215
  public void union(final String token, String name, ReadableArray value, Promise promise) throws JSONException {
164
216
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
217
+ if (instance == null) {
218
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
219
+ return;
220
+ }
165
221
  synchronized (instance) {
166
222
  JSONArray propertyValue = ReactNativeHelper.reactToJSON(value);
167
223
  instance.getPeople().union(name, propertyValue);
@@ -172,6 +228,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
172
228
  @ReactMethod
173
229
  public void getSuperProperties(final String token, Promise promise) throws JSONException {
174
230
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
231
+ if (instance == null) {
232
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
233
+ return;
234
+ }
175
235
  synchronized (instance) {
176
236
  promise.resolve(ReactNativeHelper.convertJsonToMap(instance.getSuperProperties()));
177
237
  }
@@ -180,6 +240,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
180
240
  @ReactMethod
181
241
  public void clearSuperProperties(final String token, Promise promise) {
182
242
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
243
+ if (instance == null) {
244
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
245
+ return;
246
+ }
183
247
  synchronized (instance) {
184
248
  instance.clearSuperProperties();
185
249
  promise.resolve(null);
@@ -189,6 +253,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
189
253
  @ReactMethod
190
254
  public void alias(final String token, String alias, String original, Promise promise) {
191
255
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
256
+ if (instance == null) {
257
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
258
+ return;
259
+ }
192
260
  synchronized (instance) {
193
261
  instance.alias(alias, original);
194
262
  promise.resolve(null);
@@ -198,6 +266,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
198
266
  @ReactMethod
199
267
  public void reset(final String token, Promise promise) {
200
268
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
269
+ if (instance == null) {
270
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
271
+ return;
272
+ }
201
273
  synchronized (instance) {
202
274
  instance.reset();
203
275
  promise.resolve(null);
@@ -207,6 +279,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
207
279
  @ReactMethod
208
280
  public void flush(final String token, Promise promise) {
209
281
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
282
+ if (instance == null) {
283
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
284
+ return;
285
+ }
210
286
  synchronized (instance) {
211
287
  instance.flush();
212
288
  promise.resolve(null);
@@ -216,6 +292,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
216
292
  @ReactMethod
217
293
  public void timeEvent(final String token, final String eventName, Promise promise) {
218
294
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
295
+ if (instance == null) {
296
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
297
+ return;
298
+ }
219
299
  synchronized (instance) {
220
300
  instance.timeEvent(eventName);
221
301
  promise.resolve(null);
@@ -225,6 +305,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
225
305
  @ReactMethod
226
306
  public void eventElapsedTime(final String token, final String eventName, Promise promise) {
227
307
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
308
+ if (instance == null) {
309
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
310
+ return;
311
+ }
228
312
  synchronized (instance) {
229
313
  promise.resolve(instance.eventElapsedTime(eventName));
230
314
  }
@@ -233,6 +317,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
233
317
  @ReactMethod
234
318
  public void set(final String token, ReadableMap properties, Promise promise) throws JSONException {
235
319
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
320
+ if (instance == null) {
321
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
322
+ return;
323
+ }
236
324
  synchronized (instance) {
237
325
  JSONObject sendProperties = ReactNativeHelper.reactToJSON(properties);
238
326
  AutomaticProperties.appendLibraryProperties(sendProperties);
@@ -244,6 +332,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
244
332
  @ReactMethod
245
333
  public void unset(final String token, String propertyName, Promise promise) {
246
334
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
335
+ if (instance == null) {
336
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
337
+ return;
338
+ }
247
339
  synchronized (instance) {
248
340
  instance.getPeople().unset(propertyName);
249
341
  promise.resolve(null);
@@ -253,6 +345,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
253
345
  @ReactMethod
254
346
  public void setOnce(final String token, ReadableMap properties, Promise promise) throws JSONException {
255
347
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
348
+ if (instance == null) {
349
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
350
+ return;
351
+ }
256
352
  synchronized (instance) {
257
353
  JSONObject sendProperties = ReactNativeHelper.reactToJSON(properties);
258
354
  AutomaticProperties.appendLibraryProperties(sendProperties);
@@ -264,6 +360,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
264
360
  @ReactMethod
265
361
  public void trackCharge(final String token, double charge, ReadableMap properties, Promise promise) throws JSONException {
266
362
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
363
+ if (instance == null) {
364
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
365
+ return;
366
+ }
267
367
  synchronized (instance) {
268
368
  JSONObject transactionValue = ReactNativeHelper.reactToJSON(properties);
269
369
  instance.getPeople().trackCharge(charge, transactionValue);
@@ -274,6 +374,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
274
374
  @ReactMethod
275
375
  public void clearCharges(final String token, Promise promise) {
276
376
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
377
+ if (instance == null) {
378
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
379
+ return;
380
+ }
277
381
  synchronized (instance) {
278
382
  instance.getPeople().clearCharges();
279
383
  promise.resolve(null);
@@ -284,6 +388,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
284
388
  public void increment(final String token, ReadableMap properties, Promise promise) {
285
389
  Map incrementProperties = ReactNativeHelper.toMap(properties);
286
390
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
391
+ if (instance == null) {
392
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
393
+ return;
394
+ }
287
395
  synchronized (instance) {
288
396
  instance.getPeople().increment(incrementProperties);
289
397
  promise.resolve(null);
@@ -293,6 +401,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
293
401
  @ReactMethod
294
402
  public void append(final String token, String name, Dynamic value, Promise promise) throws JSONException {
295
403
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
404
+ if (instance == null) {
405
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
406
+ return;
407
+ }
296
408
  synchronized (instance) {
297
409
  instance.getPeople().append(name, ReactNativeHelper.dynamicToObject(value));
298
410
  promise.resolve(null);
@@ -302,6 +414,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
302
414
  @ReactMethod
303
415
  public void deleteUser(final String token, Promise promise) {
304
416
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
417
+ if (instance == null) {
418
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
419
+ return;
420
+ }
305
421
  synchronized (instance) {
306
422
  instance.getPeople().deleteUser();
307
423
  promise.resolve(null);
@@ -311,6 +427,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
311
427
  @ReactMethod
312
428
  public void remove(final String token, String name, Dynamic value, Promise promise) throws JSONException {
313
429
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
430
+ if (instance == null) {
431
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
432
+ return;
433
+ }
314
434
  synchronized (instance) {
315
435
  instance.getPeople().remove(name, ReactNativeHelper.dynamicToObject(value));
316
436
  promise.resolve(null);
@@ -320,6 +440,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
320
440
  @ReactMethod
321
441
  public void trackWithGroups(final String token, String eventName, ReadableMap properties, ReadableMap groups, Promise promise) {
322
442
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
443
+ if (instance == null) {
444
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
445
+ return;
446
+ }
323
447
  synchronized (instance) {
324
448
  Map eventProperties = ReactNativeHelper.toMap(properties);
325
449
  Map eventGroups = ReactNativeHelper.toMap(groups);
@@ -332,6 +456,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
332
456
  @ReactMethod
333
457
  public void setGroup(final String token, String groupKey, Dynamic groupID, Promise promise) {
334
458
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
459
+ if (instance == null) {
460
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
461
+ return;
462
+ }
335
463
  synchronized (instance) {
336
464
  instance.setGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID));
337
465
  promise.resolve(null);
@@ -341,6 +469,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
341
469
  @ReactMethod
342
470
  public void setGroups(final String token, String groupKey, ReadableArray groupIDs, Promise promise) throws JSONException {
343
471
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
472
+ if (instance == null) {
473
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
474
+ return;
475
+ }
344
476
  synchronized (instance) {
345
477
  instance.setGroup(groupKey, Arrays.asList(ReactNativeHelper.toArray(groupIDs)));
346
478
  promise.resolve(null);
@@ -350,6 +482,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
350
482
  @ReactMethod
351
483
  public void addGroup(final String token, String groupKey, Dynamic groupID, Promise promise) {
352
484
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
485
+ if (instance == null) {
486
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
487
+ return;
488
+ }
353
489
  synchronized (instance) {
354
490
  instance.addGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID));
355
491
  promise.resolve(null);
@@ -359,6 +495,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
359
495
  @ReactMethod
360
496
  public void removeGroup(final String token, String groupKey, Dynamic groupID, Promise promise) {
361
497
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
498
+ if (instance == null) {
499
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
500
+ return;
501
+ }
362
502
  synchronized (instance) {
363
503
  instance.removeGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID));
364
504
  promise.resolve(null);
@@ -368,6 +508,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
368
508
  @ReactMethod
369
509
  public void deleteGroup(final String token, String groupKey, Dynamic groupID, Promise promise) {
370
510
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
511
+ if (instance == null) {
512
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
513
+ return;
514
+ }
371
515
  synchronized (instance) {
372
516
  instance.getGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID)).deleteGroup();
373
517
  promise.resolve(null);
@@ -377,6 +521,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
377
521
  @ReactMethod
378
522
  public void groupSetProperties(final String token, String groupKey, Dynamic groupID, ReadableMap properties, Promise promise) throws JSONException {
379
523
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
524
+ if (instance == null) {
525
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
526
+ return;
527
+ }
380
528
  synchronized (instance) {
381
529
  JSONObject sendProperties = ReactNativeHelper.reactToJSON(properties);
382
530
  instance.getGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID)).set(sendProperties);
@@ -387,6 +535,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
387
535
  @ReactMethod
388
536
  public void groupSetPropertyOnce(final String token, String groupKey, Dynamic groupID, ReadableMap properties, Promise promise) throws JSONException {
389
537
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
538
+ if (instance == null) {
539
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
540
+ return;
541
+ }
390
542
  synchronized (instance) {
391
543
  JSONObject sendProperties = ReactNativeHelper.reactToJSON(properties);
392
544
  instance.getGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID)).setOnce(sendProperties);
@@ -397,6 +549,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
397
549
  @ReactMethod
398
550
  public void groupUnsetProperty(final String token, String groupKey, Dynamic groupID, String propertyName, Promise promise) throws JSONException {
399
551
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
552
+ if (instance == null) {
553
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
554
+ return;
555
+ }
400
556
  synchronized (instance) {
401
557
  instance.getGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID)).unset(propertyName);
402
558
  promise.resolve(null);
@@ -406,6 +562,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
406
562
  @ReactMethod
407
563
  public void groupRemovePropertyValue(final String token, String groupKey, Dynamic groupID, String name, Dynamic value, Promise promise) throws JSONException {
408
564
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
565
+ if (instance == null) {
566
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
567
+ return;
568
+ }
409
569
  synchronized (instance) {
410
570
  instance.getGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID)).remove(name, ReactNativeHelper.dynamicToObject(value));
411
571
  promise.resolve(null);
@@ -415,6 +575,10 @@ public class MixpanelReactNativeModule extends ReactContextBaseJavaModule {
415
575
  @ReactMethod
416
576
  public void groupUnionProperty(final String token, String groupKey, Dynamic groupID, String name, ReadableArray values, Promise promise) throws JSONException {
417
577
  MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true);
578
+ if (instance == null) {
579
+ promise.reject("Instance Error", "Failed to get Mixpanel instance");
580
+ return;
581
+ }
418
582
  synchronized (instance) {
419
583
  JSONArray arrayValues = ReactNativeHelper.reactToJSON(values);
420
584
  instance.getGroup(groupKey, ReactNativeHelper.dynamicToObject(groupID)).union(name, arrayValues);