Skip to content

Commit a522f0b

Browse files
Method createAlias should accept two parameters; Update Android SDK to 5.6.8; Check against potential NPE (davide-scalzo#207)
* Update Android SDK to 5.6.0 * Lock iOS podspec to 3.4.4 * Updater package * Update Readme * Change implementation to api within gradle build * Update iOS Mixpanel to 3.4.5 * Lock iOS podspec to 3.4.5 * Update npm version * Update gitignore - add prefs and vsc project * Update index.d.ts - add clearSuperProperties * Add support for clearing a single registration id on Android * Udpate index.d.ts * [iOS] Pass deviceToken as string to `removePushDeviceToken` as it's convinient way to de-register iOS device * Update readme * Update npm version * Update README.md * [Android] Retrieves current Firebase Cloud Messaging token * Update readme.md and index.d.ts * [Android] Add getPushRegistrationId * Add missing definition * Update README.md * Update definitions and error messages * Update Android SDK to 5.6.3 * Update iOS podspec to 3.4.7 * Update npm version * Update dependencies version * [iOS] Podspec should take velues from package.json * Added support for tvOS * Add append method; update readme.md * Update Mixpanel.h * Added fine grained in-app message control * Add Opting Out / In The later versions of Mixpanel have the ability to opt in/out of collecting data for GDPR purposes. This adds support for those as well as updating the Mixpanel library. * Update version * Update doc * Add information about Autolinking * Add missing Platform import * Update readme; add changelog * Expose iOS params that can be passed on Mixpanel instance initalization: trackCrashes, automaticPushTracking, launchOptions * Fix typo * [iOS] Add missing MixpanelType.h file * Method createAlias should accept two parameters * Update mixpanel-android to 5.6.8 * Update package.json * Update CHANGELOG.md * Update README.md * Add check against potential NPE * Update package.json * Update CHANGELOG.md Co-authored-by: Davide Scalzo <scalzodavide@yahoo.it>
1 parent 8ae4c21 commit a522f0b

File tree

10 files changed

+123
-30
lines changed

10 files changed

+123
-30
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# 1.1.14
2+
3+
- [Android] Add check against potential NPE
4+
- Update Readme
5+
6+
# 1.1.13
7+
8+
- [Android] Update mixpanel-android SDK to 5.6.8
9+
10+
# 1.1.12
11+
12+
- Method createAlias should accept two parameters (https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-alias). Second parameter is optional to keep backward compatabiluty. Will fallback to distinctID generated by mixpanel instance.
13+
14+
# 1.1.11
15+
16+
- [iOS] Add missing file
17+
118
# 1.1.10
219

320
- Fix typo
@@ -19,4 +36,4 @@
1936
- Add push / registration methods
2037
- Update README
2138
- Update Typescript defs
22-
- Fix crash on clearPushRegistrationId
39+
- Fix crash on clearPushRegistrationId

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,41 @@ Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true, true, null);
124124
// Use this method to opt in an already opted out user from tracking. People updates and track calls will be sent to Mixpanel after using this method.
125125
Mixpanel.optInTracking();
126126

127-
// Opt out tracking.
127+
// Opt out tracking.
128128

129-
// This method is used to opt out tracking. This causes all events and people request no longer to be sent back to the Mixpanel server.
129+
// This method is used to opt out tracking. This causes all events and people request no longer to be sent back to the Mixpanel server.
130130
Mixpanel.optOutTracking();
131131

132-
//Send and event name with no properties
132+
// Send and event name with no properties
133133
Mixpanel.track("Event name");
134134

135-
//Track event with properties
135+
// Track event with properties
136136
Mixpanel.trackWithProperties('Click Button', {button_type: 'yellow button', button_text: 'magic button'});
137137

138-
//Create Alias from unique id, i.e. create a new mixpanel profile: to call when a user signs up, with a unique id that is not used by another mixpanel profile as param
138+
// Create Alias from unique id, i.e. create a new mixpanel profile: to call when a user signs up, with a unique id that is not used by another mixpanel profile as param
139139
Mixpanel.createAlias(UNIQUE_ID)
140140

141-
//Identify, i.e. associate to an existing mixpanel profile: to call when a user logs in and is already registered in Mixpanel with this unique id
141+
// OR:
142+
143+
// Create an alias, which Mixpanel will use to link two distinct_ids going forward (not retroactively). Multiple aliases can map to the same original ID, but not vice-versa.
144+
// Aliases can also be chained - the following is a valid scenario:
145+
Mixpanel.createAlias('new_id', 'existing_id');
146+
...
147+
Mixpanel.createAlias('newer_id', 'new_id');
148+
// If the original ID is not passed in, we will use the current distinct_id - probably the auto-generated GUID.
149+
// Notes:
150+
// The best practice is to call createAlias() when a unique ID is first created for a user (e.g., when a user first registers for
151+
// an account and provides an email address). createAlias() should never be called more than once for a given user, except to chain
152+
// a newer ID to a previously new ID, as described above.
153+
// More info about createAlias: https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-alias
154+
155+
// Identify, i.e. associate to an existing mixpanel profile: to call when a user logs in and is already registered in Mixpanel with this unique id
142156
Mixpanel.identify(UNIQUE_ID)
143157

144-
//Set People properties (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
158+
// Set People properties (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
145159
Mixpanel.set({"$email": "elvis@email.com"});
146160

147-
//Set People Properties Once (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
161+
// Set People Properties Once (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
148162
Mixpanel.setOnce({"$email": "elvis@email.com", "Created": new Date().toISOString()});
149163

150164
// Timing Events
@@ -275,5 +289,7 @@ You can then call the following in your react native application:
275289
Mixpanel.showInAppMessageIfAvailable();
276290
```
277291

292+
More info: https://developer.mixpanel.com/docs/android-inapp-messages
293+
278294
## Notes ##
279295
For more info please have a look at the [official Mixpanel reference](https://mixpanel.com/help/reference/ios) for iOS

RNMixpanel.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
/* Begin PBXFileReference section */
4040
5EAEEA411F0555B100C6FED8 /* libRNMixpanel-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRNMixpanel-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
41+
E7588479238556670081D7FF /* MixpanelType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MixpanelType.h; sourceTree = "<group>"; };
4142
E78DD5BC2364BED0009197B6 /* MixpanelPeople.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MixpanelPeople.h; sourceTree = "<group>"; };
4243
FDC64AF01BF1690D0044C1B4 /* libRNMixpanel.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMixpanel.a; sourceTree = BUILT_PRODUCTS_DIR; };
4344
FDC64AF31BF1690D0044C1B4 /* RNMixpanel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMixpanel.h; sourceTree = "<group>"; };
@@ -88,6 +89,7 @@
8889
isa = PBXGroup;
8990
children = (
9091
E78DD5BC2364BED0009197B6 /* MixpanelPeople.h */,
92+
E7588479238556670081D7FF /* MixpanelType.h */,
9193
FDDAC2A11BF2B66500E70D3C /* Mixpanel.h */,
9294
FDC64AF31BF1690D0044C1B4 /* RNMixpanel.h */,
9395
FDC64AF51BF1690D0044C1B4 /* RNMixpanel.m */,

RNMixpanel/MixpanelType.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// MixpanelType.h
3+
// Mixpanel
4+
//
5+
// Created by Weizhe Yuan on 9/6/18.
6+
// Copyright © 2018 Mixpanel. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@protocol MixpanelType <NSObject>
12+
13+
- (BOOL)equalToMixpanelType:(id<MixpanelType>)rhs;
14+
15+
@end
16+
17+
@interface NSString (MixpanelTypeCategory) <MixpanelType>
18+
19+
@end
20+
21+
@interface NSNumber (MixpanelTypeCategory) <MixpanelType>
22+
23+
@end
24+
25+
@interface NSArray (MixpanelTypeCategory) <MixpanelType>
26+
27+
@end
28+
29+
@interface NSDictionary (MixpanelTypeCategory) <MixpanelType>
30+
31+
@end
32+
33+
@interface NSDate (MixpanelTypeCategory) <MixpanelType>
34+
35+
@end
36+
37+
@interface NSURL (MixpanelTypeCategory) <MixpanelType>
38+
39+
@end

RNMixpanel/RNMixpanel.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ -(Mixpanel*) getInstance: (NSString *)name {
124124
}
125125

126126
// create Alias
127-
RCT_EXPORT_METHOD(createAlias:(NSString *)old_id
127+
RCT_EXPORT_METHOD(createAlias:(NSString *)alias
128+
oldDistinctID:(nullable NSString *)oldDistinctID
128129
apiToken:(NSString *)apiToken
129130
resolve:(RCTPromiseResolveBlock)resolve
130131
reject:(RCTPromiseRejectBlock)reject) {
131-
[[self getInstance:apiToken] createAlias:old_id forDistinctID:[self getInstance:apiToken].distinctId];
132+
NSString *distinctId = oldDistinctID ? oldDistinctID : [self getInstance:apiToken].distinctId;
133+
[[self getInstance:apiToken] createAlias:alias forDistinctID:distinctId];
132134
resolve(nil);
133135
}
134136

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ android {
1717

1818
dependencies {
1919
implementation 'com.facebook.react:react-native:+'
20-
api "com.mixpanel.android:mixpanel-android:5.6.5"
20+
api "com.mixpanel.android:mixpanel-android:5.6.8"
2121
}

android/src/main/java/com/kevinejohn/RNMixpanel/RNMixpanelModule.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,20 @@ public void trackWithProperties(final String name, final ReadableMap properties,
182182

183183
final MixpanelAPI instance = getInstance(apiToken);
184184
synchronized(instance) {
185-
instance.track(name, obj);
185+
if (obj != null) {
186+
instance.track(name, obj);
187+
}
186188
}
187189
promise.resolve(null);
188190
}
189191

190192

191193
@ReactMethod
192-
public void createAlias(final String old_id, final String apiToken, Promise promise) {
194+
public void createAlias(final String alias, final String oldDistinctID, final String apiToken, Promise promise) {
193195
final MixpanelAPI instance = getInstance(apiToken);
194196
synchronized(instance) {
195-
instance.alias(old_id, instance.getDistinctId());
197+
String distinctID = (oldDistinctID != null) ? oldDistinctID : instance.getDistinctId();
198+
instance.alias(alias, distinctID);
196199
}
197200
promise.resolve(null);
198201
}
@@ -226,7 +229,9 @@ public void registerSuperProperties(final ReadableMap properties, final String a
226229
}
227230
final MixpanelAPI instance = getInstance(apiToken);
228231
synchronized(instance) {
229-
instance.registerSuperProperties(obj);
232+
if (obj != null) {
233+
instance.registerSuperProperties(obj);
234+
}
230235
}
231236
promise.resolve(null);
232237
}
@@ -241,7 +246,9 @@ public void registerSuperPropertiesOnce(final ReadableMap properties, final Stri
241246
}
242247
final MixpanelAPI instance = getInstance(apiToken);
243248
synchronized(instance) {
244-
instance.registerSuperPropertiesOnce(obj);
249+
if (obj != null) {
250+
instance.registerSuperPropertiesOnce(obj);
251+
}
245252
}
246253
promise.resolve(null);
247254
}
@@ -275,7 +282,9 @@ public void set(final ReadableMap properties, final String apiToken, Promise pro
275282

276283
final MixpanelAPI instance = getInstance(apiToken);
277284
synchronized(instance) {
278-
instance.getPeople().set(obj);
285+
if (obj != null) {
286+
instance.getPeople().set(obj);
287+
}
279288
}
280289
promise.resolve(null);
281290
}
@@ -290,7 +299,9 @@ public void setOnce(final ReadableMap properties, final String apiToken, Promise
290299
}
291300
final MixpanelAPI instance = getInstance(apiToken);
292301
synchronized(instance) {
293-
instance.getPeople().setOnce(obj);
302+
if (obj != null) {
303+
instance.getPeople().setOnce(obj);
304+
}
294305
}
295306
promise.resolve(null);
296307
}
@@ -351,7 +362,9 @@ public void trackChargeWithProperties(final double charge, final ReadableMap pro
351362
}
352363
final MixpanelAPI instance = getInstance(apiToken);
353364
synchronized(instance) {
354-
instance.getPeople().trackCharge(charge, obj);
365+
if (obj != null) {
366+
instance.getPeople().trackCharge(charge, obj);
367+
}
355368
}
356369
promise.resolve(null);
357370
}
@@ -375,7 +388,9 @@ public void union(final String name, final ReadableArray properties, final Strin
375388
}
376389
final MixpanelAPI instance = getInstance(apiToken);
377390
synchronized(instance) {
378-
instance.getPeople().union(name, obj);
391+
if (obj != null) {
392+
instance.getPeople().union(name, obj);
393+
}
379394
}
380395
promise.resolve(null);
381396
}
@@ -390,7 +405,9 @@ public void append(final String name, final ReadableArray properties, final Stri
390405
}
391406
final MixpanelAPI instance = getInstance(apiToken);
392407
synchronized(instance) {
393-
instance.getPeople().append(name, obj);
408+
if (obj != null) {
409+
instance.getPeople().append(name, obj);
410+
}
394411
}
395412
promise.resolve(null);
396413
}

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare module 'react-native-mixpanel' {
88
track(event: string, properties?: Object): Promise<void>
99
flush(): Promise<void>
1010
disableIpAddressGeolocalization(): Promise<void>
11-
alias(alias: string): Promise<void>
11+
alias(alias: string, oldDistinctID?: string): Promise<void>
1212
identify(userId: string): Promise<void>
1313
timeEvent(event: string): Promise<void>
1414
registerSuperProperties(properties: Object): Promise<void>
@@ -46,7 +46,7 @@ declare module 'react-native-mixpanel' {
4646
trackWithProperties(event: string, properties: Object): void;
4747
flush(): void;
4848
disableIpAddressGeolocalization(): void;
49-
createAlias(alias: string): void;
49+
createAlias(alias: string, oldDistinctID?: string): void;
5050
identify(userId: string): void;
5151
timeEvent(event: string): void;
5252
registerSuperProperties(properties: Object): void;

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export class MixpanelInstance {
102102
return RNMixpanel.disableIpAddressGeolocalization(this.apiToken)
103103
}
104104

105-
alias(alias: string): Promise<void> {
105+
alias(alias: string, oldDistinctID?: string): Promise<void> {
106106
if (!this.initialized) throw new Error(uninitializedError('createAlias'))
107107

108-
return RNMixpanel.createAlias(alias, this.apiToken)
108+
return RNMixpanel.createAlias(alias, oldDistinctID, this.apiToken)
109109
}
110110

111111
identify(userId: string): Promise<void> {
@@ -331,10 +331,10 @@ export default {
331331
defaultInstance.disableIpAddressGeolocalization()
332332
},
333333

334-
createAlias(alias: string) {
334+
createAlias(alias: string, oldDistinctID: ?string = null) {
335335
if (!defaultInstance) throw new Error(NO_INSTANCE_ERROR)
336336

337-
defaultInstance.alias(alias)
337+
defaultInstance.alias(alias, oldDistinctID)
338338
},
339339

340340
identify(userId: string) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-mixpanel",
3-
"version": "1.1.10",
3+
"version": "1.1.14",
44
"description": "A React Native wrapper for Mixpanel tracking",
55
"main": "index.js",
66
"repository": {
@@ -19,4 +19,4 @@
1919
"url": "https://github.com/davodesign84/react-native-mixpanel/issues"
2020
},
2121
"homepage": "https://github.com/davodesign84/react-native-mixpanel#readme"
22-
}
22+
}

0 commit comments

Comments
 (0)