From 91e50011d37075bb95e8c99f6518eaae0471e251 Mon Sep 17 00:00:00 2001 From: Zihe Jia Date: Fri, 1 Dec 2023 13:59:45 -0800 Subject: [PATCH 1/5] bump ios to 4.2.0 and android to 7.3.2 --- MixpanelReactNative.podspec | 2 +- android/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MixpanelReactNative.podspec b/MixpanelReactNative.podspec index a30b466a..44fa1e7d 100644 --- a/MixpanelReactNative.podspec +++ b/MixpanelReactNative.podspec @@ -19,5 +19,5 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } s.dependency "React-Core" - s.dependency "Mixpanel-swift", '4.1.3' + s.dependency "Mixpanel-swift", '4.2.0' end diff --git a/android/build.gradle b/android/build.gradle index 26efaa38..6744f885 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,5 +34,5 @@ repositories { dependencies { implementation 'com.facebook.react:react-native:+' - implementation 'com.mixpanel.android:mixpanel-android:7.3.1' + implementation 'com.mixpanel.android:mixpanel-android:7.3.2' } From 750352e7c368962f897a866a39751e4fea79a2dc Mon Sep 17 00:00:00 2001 From: Zihe Jia Date: Fri, 1 Dec 2023 14:32:35 -0800 Subject: [PATCH 2/5] add api setFlushBatchSize --- .../reactnative/MixpanelReactNativeModule.java | 16 +++++++++++++++- index.js | 12 ++++++++++++ ios/MixpanelReactNative.m | 2 ++ ios/MixpanelReactNative.swift | 10 ++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java b/android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java index aba52321..d5002dd8 100644 --- a/android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java +++ b/android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java @@ -55,7 +55,8 @@ public void setServerURL(final String token, final String serverURL, Promise pro } @ReactMethod - public void setUseIpAddressForGeolocation(final String token, boolean useIpAddressForGeolocation, Promise promise) throws JSONException { + public void setUseIpAddressForGeolocation(final String token, boolean useIpAddressForGeolocation, Promise promise) + throws JSONException { MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true); if (instance == null) { promise.reject("Instance Error", "Failed to get Mixpanel instance"); @@ -67,6 +68,19 @@ public void setUseIpAddressForGeolocation(final String token, boolean useIpAddre } } + @ReactMethod + public void setFlushBatchSize(final String token, Integer flushBatchSize, Promise promise) throws JSONException { + MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true); + if (instance == null) { + promise.reject("Instance Error", "Failed to get Mixpanel instance"); + return; + } + synchronized (instance) { + instance.setFlushBatchSize(flushBatchSize); + promise.resolve(null); + } + } + @ReactMethod public void setLoggingEnabled(final String token, boolean enableLogging, Promise promise) throws JSONException { MixpanelAPI instance = MixpanelAPI.getInstance(this.mReactContext, token, true); diff --git a/index.js b/index.js index ab072839..6ad52398 100644 --- a/index.js +++ b/index.js @@ -140,6 +140,18 @@ export class Mixpanel { setUseIpAddressForGeolocation(useIpAddressForGeolocation) { MixpanelReactNative.setUseIpAddressForGeolocation(this.token, useIpAddressForGeolocation); } + + /** + * Set the number of events sent in a single network request to the Mixpanel server. + * 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. + * + * @param {integer} flushBatchSize whether to automatically send the client IP Address. + * Defaults to true. + * + */ + setFlushBatchSize(flushBatchSize) { + MixpanelReactNative.setFlushBatchSize(this.token, flushBatchSize); + } /** * Will return true if the user has opted out from tracking. diff --git a/ios/MixpanelReactNative.m b/ios/MixpanelReactNative.m index fa11b90d..21115859 100644 --- a/ios/MixpanelReactNative.m +++ b/ios/MixpanelReactNative.m @@ -16,6 +16,8 @@ @interface RCT_EXTERN_MODULE(MixpanelReactNative, NSObject) RCT_EXTERN_METHOD(setUseIpAddressForGeolocation:(NSString *)token useIpAddressForGeolocation:(BOOL)useIpAddressForGeolocation resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(setFlushBatchSize:(NSString *)token flushBatchSize:(NSInteger)flushBatchSize resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) + // MARK: - Opting Users Out of Tracking RCT_EXTERN_METHOD(optOutTracking:(NSString *)token resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) diff --git a/ios/MixpanelReactNative.swift b/ios/MixpanelReactNative.swift index 56c0e29c..106bdb58 100644 --- a/ios/MixpanelReactNative.swift +++ b/ios/MixpanelReactNative.swift @@ -59,6 +59,16 @@ open class MixpanelReactNative: NSObject { resolve(nil) } + @objc + func setFlushBatchSize(_ token: String, + flushBatchSize: Int, + resolver resolve: RCTPromiseResolveBlock, + rejecter reject: RCTPromiseRejectBlock) -> Void { + let instance = MixpanelReactNative.getMixpanelInstance(token) + instance?.flushBatchSize = flushBatchSize + resolve(nil) + } + @objc func setUseIpAddressForGeolocation(_ token: String, useIpAddressForGeolocation: Bool, From 725749e6f3e018a3f2466f6d72cf69770c3e146c Mon Sep 17 00:00:00 2001 From: Zihe Jia Date: Fri, 1 Dec 2023 14:57:32 -0800 Subject: [PATCH 3/5] add test for setFlushBatchSize --- __tests__/index.test.js | 6 ++++++ index.js | 1 + 2 files changed, 7 insertions(+) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 16fc438d..ffe77e38 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -36,6 +36,12 @@ test(`it calls MixpanelReactNative setUseIpAddressForGeolocation`, async () => { expect(NativeModules.MixpanelReactNative.setUseIpAddressForGeolocation).toBeCalledWith("token", true); }); +test(`it calls MixpanelReactNative setFlushBatchSize`, async () => { + const mixpanel = await Mixpanel.init("token", true); + mixpanel.setFlushBatchSize(20); + expect(NativeModules.MixpanelReactNative.setFlushBatchSize).toBeCalledWith("token", true); +}); + test(`it calls MixpanelReactNative hasOptedOutTracking`, async () => { const mixpanel = await Mixpanel.init("token", true); mixpanel.hasOptedOutTracking(); diff --git a/index.js b/index.js index 6ad52398..8baa362a 100644 --- a/index.js +++ b/index.js @@ -153,6 +153,7 @@ export class Mixpanel { MixpanelReactNative.setFlushBatchSize(this.token, flushBatchSize); } + /** * Will return true if the user has opted out from tracking. * From 2f01152e63ae553feb954f8d7e1a41288516520b Mon Sep 17 00:00:00 2001 From: Zihe Jia Date: Fri, 1 Dec 2023 15:39:02 -0800 Subject: [PATCH 4/5] fix tests --- __tests__/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index ffe77e38..25b351f4 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -39,7 +39,7 @@ test(`it calls MixpanelReactNative setUseIpAddressForGeolocation`, async () => { test(`it calls MixpanelReactNative setFlushBatchSize`, async () => { const mixpanel = await Mixpanel.init("token", true); mixpanel.setFlushBatchSize(20); - expect(NativeModules.MixpanelReactNative.setFlushBatchSize).toBeCalledWith("token", true); + expect(NativeModules.MixpanelReactNative.setFlushBatchSize).toBeCalledWith("token", 20); }); test(`it calls MixpanelReactNative hasOptedOutTracking`, async () => { From 17e6ef4119f2f855b9be8d574875b7786f4de905 Mon Sep 17 00:00:00 2001 From: Zihe Jia Date: Fri, 1 Dec 2023 16:04:29 -0800 Subject: [PATCH 5/5] add typescript def --- __tests__/jest_setup.js | 1 + index.d.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/__tests__/jest_setup.js b/__tests__/jest_setup.js index 0f1fb8d6..76e9d9e4 100644 --- a/__tests__/jest_setup.js +++ b/__tests__/jest_setup.js @@ -22,6 +22,7 @@ jest.doMock('react-native', () => { setLoggingEnabled: jest.fn(), setFlushOnBackground: jest.fn(), setUseIpAddressForGeolocation: jest.fn(), + setFlushBatchSize: jest.fn(), hasOptedOutTracking: jest.fn(), optInTracking: jest.fn(), optOutTracking: jest.fn(), diff --git a/index.d.ts b/index.d.ts index 0e4e3584..62cf6d46 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,8 +8,8 @@ export class Mixpanel { setServerURL(serverURL: string): void; setLoggingEnabled(loggingEnabled: boolean): void; setFlushOnBackground(flushOnBackground: boolean): void; - setUseIpAddressForGeolocation(useIpAddressForGeolocation: boolean): void; + setFlushBatchSize(flushBatchSize: number): void; hasOptedOutTracking(): Promise; optInTracking(): void; optOutTracking(): void;