Skip to content

Commit

Permalink
Merge pull request #9 from lorenc-tomasz/1.2.8
Browse files Browse the repository at this point in the history
1.2.8
  • Loading branch information
lorenc-tomasz authored Sep 28, 2020
2 parents 4b1daa8 + 0084274 commit a0119d4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.2.8

- Unify how `reset()` method works on iOS and Android. This change should close an issue: https://github.com/davodesign84/react-native-mixpanel/issues/258 `reset()` method will contain new params: `flushOnReset` and `autoGenerateNewUniqueId`. Reset method is backward compatible. More in README.md
- Fix `sharedInstanceWithToken` method definition


# 1.2.7

- [Android] Update SDK to 5.8.5 (https://github.com/mixpanel/mixpanel-android/releases/tag/v5.8.5)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ Mixpanel.removePushDeviceToken(pushDeviceToken: string);
// Unregister the given device to receive push notifications.
Mixpanel.removeAllPushDeviceTokens();

// Mixpanel reset method (warning: it will also generate a new unique id and call the identify method with it. Thus, the user will not be anonymous in Mixpanel.)
// Mixpanel reset method (warning: by default it will also generate a new unique id and call the identify method with it. Thus, the user will not be anonymous in Mixpanel.)
// @param flushOnReset - will flush data on reset (default value: true)
// @param autoGenerateNewUniqueId - determines if new unique id should be generated automaticaly or not (default value: true)
Mixpanel.reset();
Mixpanel.reset(false);
Mixpanel.reset(true, false);

// get the last distinct id set with identify or, if identify hasn't been
// called, the default mixpanel id for this device.
Expand Down
14 changes: 12 additions & 2 deletions RNMixpanel/RNMixpanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,21 @@ -(Mixpanel*) getInstance: (NSString *)name {

// reset
RCT_EXPORT_METHOD(reset:(NSString *)apiToken
flushOnReset:(BOOL)flushOnReset
autoGenerateNewUniqueId:(BOOL)autoGenerateNewUniqueId
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
if (flushOnReset) {
[[self getInstance:apiToken] flush];
}

[[self getInstance:apiToken] reset];
NSString *uuid = [[NSUUID UUID] UUIDString];
[[self getInstance:apiToken] identify:uuid];

if (autoGenerateNewUniqueId) {
NSString *uuid = [[NSUUID UUID] UUIDString];
[[self getInstance:apiToken] identify:uuid];
}

resolve(nil);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
* Mixpanel React Native module.
Expand Down Expand Up @@ -415,11 +416,18 @@ public void append(final String name, final ReadableArray properties, final Stri
}

@ReactMethod
public void reset(final String apiToken, Promise promise) {
public void reset(final String apiToken, final Boolean flushOnReset, final Boolean autoGenerateNewUniqueId, Promise promise) {
final MixpanelAPI instance = getInstance(apiToken);
synchronized(instance) {
if (flushOnReset) {
instance.flush();
}
instance.reset();
instance.flush();
if (autoGenerateNewUniqueId) {
String uniqueId = UUID.randomUUID().toString();
instance.identify(uniqueId);
instance.getPeople().identify(uniqueId);
}
}
promise.resolve(null);
}
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare module 'react-native-mixpanel' {
union(name: string, properties: any[]): Promise<void>
append(name: string, properties: any[]): Promise<void>
clearSuperProperties(): Promise<void>
reset(): Promise<void>
reset(flushOnReset?: boolean, autoGenerateNewUniqueId?: boolean): Promise<void>
showInAppMessageIfAvailable(): Promise<void>
optInTracking(): Promise<void>
optOutTracking(): Promise<void>
Expand Down Expand Up @@ -63,7 +63,7 @@ declare module 'react-native-mixpanel' {
union(name: string, properties: any[]): void;
append(name: string, properties: any[]): void;
clearSuperProperties(): void;
reset(): void;
reset(flushOnReset?: boolean, autoGenerateNewUniqueId?: boolean): void;
showInAppMessageIfAvailable(): void;
optInTracking(): void;
optOutTracking(): void;
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ export class MixpanelInstance {
return RNMixpanel.clearPushRegistrationId(token, this.apiToken)
}

reset(): Promise<void> {
reset(flushOnReset?: boolean = true, autoGenerateNewUniqueId?: boolean = true): Promise<void> {
if (!this.initialized) throw new Error(uninitializedError('reset'))

return RNMixpanel.reset(this.apiToken)
return RNMixpanel.reset(this.apiToken, flushOnReset, autoGenerateNewUniqueId)
}

showInAppMessageIfAvailable(): Promise<void> {
Expand Down Expand Up @@ -278,7 +278,7 @@ mixpanel.track('my event')
export default {

sharedInstanceWithToken(apiToken: string, optOutTrackingDefault: ?boolean = false, trackCrashes: ?boolean = true, automaticPushTracking: ?boolean = true, launchOptions: ?Object = null): Promise<void> {
const instance = new MixpanelInstance(apiToken, optOutTrackingDefault)
const instance = new MixpanelInstance(apiToken, optOutTrackingDefault, trackCrashes, automaticPushTracking, launchOptions)
if (!defaultInstance) defaultInstance = instance
return instance.initialize()
},
Expand Down Expand Up @@ -475,10 +475,10 @@ export default {
defaultInstance.clearPushRegistrationId(token)
},

reset() {
reset(flushOnReset?: boolean = true, autoGenerateNewUniqueId?: boolean = true) {
if (!defaultInstance) throw new Error(NO_INSTANCE_ERROR)

defaultInstance.reset()
defaultInstance.reset(flushOnReset, autoGenerateNewUniqueId)
},

showInAppMessageIfAvailable() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-mixpanel",
"version": "1.2.7",
"version": "1.2.8",
"description": "A React Native wrapper for Mixpanel tracking",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit a0119d4

Please sign in to comment.