From bd8251e9e4aad0614f956a978f5e85abe5ad09d3 Mon Sep 17 00:00:00 2001 From: MarcinusX Date: Fri, 18 Feb 2022 11:57:06 +0100 Subject: [PATCH 1/5] Add Mixpanel integration --- android/build.gradle | 1 + .../flutter_segment/FlutterSegmentOptions.java | 14 +++++++++++--- .../flutter_segment/FlutterSegmentPlugin.java | 4 ++++ ios/Classes/FlutterSegmentPlugin.m | 9 +++++++++ ios/flutter_segment.podspec | 1 + lib/src/segment_config.dart | 4 +++- 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 794d5040..3247571a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -36,6 +36,7 @@ android { dependencies { implementation 'com.segment.analytics.android:analytics:4.10.0' implementation 'com.segment.analytics.android.integrations:amplitude:3.0.3' + implementation 'com.segment.analytics.android.integrations:mixpanel:2.3.2' } } diff --git a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java index 3b225b0d..4a98b4e9 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java @@ -8,12 +8,14 @@ public class FlutterSegmentOptions { private final String writeKey; private final Boolean trackApplicationLifecycleEvents; private final Boolean amplitudeIntegrationEnabled; + private final Boolean mixpanelIntegrationEnabled; private final Boolean debug; - public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents, Boolean amplitudeIntegrationEnabled,Boolean debug) { + public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents, Boolean amplitudeIntegrationEnabled, Boolean mixpanelntegrationEnabled, Boolean debug) { this.writeKey = writeKey; this.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; this.amplitudeIntegrationEnabled = amplitudeIntegrationEnabled; + this.mixpanelIntegrationEnabled = mixpanelntegrationEnabled; this.debug = debug; } @@ -29,6 +31,10 @@ public Boolean isAmplitudeIntegrationEnabled() { return amplitudeIntegrationEnabled; } + public Boolean isMixpanelIntegrationEnabled() { + return mixpanelIntegrationEnabled; + } + public Boolean getDebug() { return debug; } @@ -37,16 +43,18 @@ static FlutterSegmentOptions create(Bundle bundle) { String writeKey = bundle.getString("com.claimsforce.segment.WRITE_KEY"); Boolean trackApplicationLifecycleEvents = bundle.getBoolean("com.claimsforce.segment.TRACK_APPLICATION_LIFECYCLE_EVENTS"); Boolean isAmplitudeIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_AMPLITUDE_INTEGRATION", false); + Boolean isMixpanelIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_MIXPANEL_INTEGRATION", false); Boolean debug = bundle.getBoolean("com.claimsforce.segment.DEBUG", false); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, debug); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, debug); } static FlutterSegmentOptions create(HashMap options) { String writeKey = (String) options.get("writeKey"); Boolean trackApplicationLifecycleEvents = (Boolean) options.get("trackApplicationLifecycleEvents"); Boolean isAmplitudeIntegrationEnabled = orFalse((Boolean) options.get("amplitudeIntegrationEnabled")); + Boolean isMixpanelIntegrationEnabled = orFalse((Boolean) options.get("mixpanelIntegrationEnabled")); Boolean debug = orFalse((Boolean) options.get("debug")); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, debug); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, debug); } private static Boolean orFalse(Boolean value) { diff --git a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java index 547e21e4..2944f381 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java @@ -15,6 +15,7 @@ import com.segment.analytics.Middleware; import com.segment.analytics.integrations.BasePayload; import com.segment.analytics.android.integrations.amplitude.AmplitudeIntegration; +import com.segment.analytics.android.integrations.mixpanel.MixpanelIntegration; import static com.segment.analytics.Analytics.LogLevel; import java.util.LinkedHashMap; @@ -86,6 +87,9 @@ private void setupChannels(FlutterSegmentOptions options) { if (options.isAmplitudeIntegrationEnabled()) { analyticsBuilder.use(AmplitudeIntegration.FACTORY); } + if (options.isMixpanelIntegrationEnabled()) { + analyticsBuilder.use(MixpanelIntegration.FACTORY); + } // Here we build a middleware that just appends data to the current context // using the [deepMerge] strategy. diff --git a/ios/Classes/FlutterSegmentPlugin.m b/ios/Classes/FlutterSegmentPlugin.m index b5aea645..d31d07b0 100644 --- a/ios/Classes/FlutterSegmentPlugin.m +++ b/ios/Classes/FlutterSegmentPlugin.m @@ -3,6 +3,7 @@ #import #import #import +#import @implementation FlutterSegmentPlugin // Contents to be appended to the context @@ -347,6 +348,7 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile { NSString *writeKey = [dict objectForKey: @"com.claimsforce.segment.WRITE_KEY"]; BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"com.claimsforce.segment.TRACK_APPLICATION_LIFECYCLE_EVENTS"] boolValue]; BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_AMPLITUDE_INTEGRATION"] boolValue]; + BOOL isMixpanelIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_MIXPANEL_INTEGRATION"] boolValue]; if(!writeKey) { return nil; } @@ -356,6 +358,9 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile { if (isAmplitudeIntegrationEnabled) { [configuration use:[SEGAmplitudeIntegrationFactory instance]]; } + if (isMixpanelIntegrationEnabled) { + [configuration use:[SEGMixpanelIntegrationFactory instance]]; + } return configuration; } @@ -364,12 +369,16 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict { NSString *writeKey = [dict objectForKey: @"writeKey"]; BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"trackApplicationLifecycleEvents"] boolValue]; BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"amplitudeIntegrationEnabled"] boolValue]; + BOOL isMixpanelIntegrationEnabled = [[dict objectForKey: @"mixpanelIntegrationEnabled"] boolValue]; SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey]; configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; if (isAmplitudeIntegrationEnabled) { [configuration use:[SEGAmplitudeIntegrationFactory instance]]; } + if (isMixpanelIntegrationEnabled) { + [configuration use:[SEGMixpanelIntegrationFactory instance]]; + } return configuration; } diff --git a/ios/flutter_segment.podspec b/ios/flutter_segment.podspec index dd86f8d1..f3c9a518 100644 --- a/ios/flutter_segment.podspec +++ b/ios/flutter_segment.podspec @@ -17,6 +17,7 @@ A new flutter plugin project. s.dependency 'Flutter' s.dependency 'Analytics', '4.1.6' s.dependency 'Segment-Amplitude', '3.3.2' + s.dependency 'Segment-Mixpanel', '1.7.2' s.ios.deployment_target = '11.0' # Added because Segment-Amplitude dependencies on iOS cause this error: diff --git a/lib/src/segment_config.dart b/lib/src/segment_config.dart index 906cda69..100e0299 100644 --- a/lib/src/segment_config.dart +++ b/lib/src/segment_config.dart @@ -3,19 +3,21 @@ class SegmentConfig { required this.writeKey, this.trackApplicationLifecycleEvents = false, this.amplitudeIntegrationEnabled = false, + this.mixpanelIntegrationEnabled = false, this.debug = false, }); final String writeKey; final bool trackApplicationLifecycleEvents; final bool amplitudeIntegrationEnabled; + final bool mixpanelIntegrationEnabled; final bool debug; Map toMap() { return { 'writeKey': writeKey, 'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents, - 'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled, + 'mixpanelIntegrationEnabled': mixpanelIntegrationEnabled, 'debug': debug, }; } From a9f42e9cb462501f975bafcf1e2e1150373b629a Mon Sep 17 00:00:00 2001 From: MarcinusX Date: Fri, 18 Feb 2022 11:59:03 +0100 Subject: [PATCH 2/5] Fix accidentally removed line --- lib/src/segment_config.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/segment_config.dart b/lib/src/segment_config.dart index 100e0299..ae37b689 100644 --- a/lib/src/segment_config.dart +++ b/lib/src/segment_config.dart @@ -17,6 +17,7 @@ class SegmentConfig { return { 'writeKey': writeKey, 'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents, + 'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled, 'mixpanelIntegrationEnabled': mixpanelIntegrationEnabled, 'debug': debug, }; From bf5dadafc36ada199c0559dd22fcca94a46cc985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Sza=C5=82ek?= Date: Tue, 14 Jun 2022 15:56:28 +0200 Subject: [PATCH 3/5] [Android] Update Segment and Amplitude integration --- android/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 3247571a..3430d495 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,12 +34,12 @@ android { } dependencies { - implementation 'com.segment.analytics.android:analytics:4.10.0' - implementation 'com.segment.analytics.android.integrations:amplitude:3.0.3' + implementation 'com.segment.analytics.android:analytics:4.10.4' + implementation 'com.segment.analytics.android.integrations:amplitude:3.1.0' implementation 'com.segment.analytics.android.integrations:mixpanel:2.3.2' } } dependencies { testImplementation 'junit:junit:4.12' -} \ No newline at end of file +} From 5d8b568556fbeb031efb8c7a95fc94c3dd5d4b65 Mon Sep 17 00:00:00 2001 From: MarcinusX Date: Wed, 27 Jul 2022 13:40:14 +0200 Subject: [PATCH 4/5] Add AppsFlyer integration --- android/build.gradle | 2 ++ android/src/main/AndroidManifest.xml | 2 ++ .../flutter_segment/FlutterSegmentOptions.java | 14 +++++++++++--- .../flutter_segment/FlutterSegmentPlugin.java | 4 ++++ ios/Classes/FlutterSegmentPlugin.m | 9 +++++++++ ios/flutter_segment.podspec | 1 + lib/src/segment_config.dart | 3 +++ 7 files changed, 32 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 3430d495..17a6a98c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -37,6 +37,8 @@ android { implementation 'com.segment.analytics.android:analytics:4.10.4' implementation 'com.segment.analytics.android.integrations:amplitude:3.1.0' implementation 'com.segment.analytics.android.integrations:mixpanel:2.3.2' + implementation 'com.appsflyer:segment-android-integration:6.5.2' + implementation 'com.android.installreferrer:installreferrer:2.1' } } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 48d11960..13155f53 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,6 @@ + + diff --git a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java index 4a98b4e9..3087461a 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java @@ -9,13 +9,15 @@ public class FlutterSegmentOptions { private final Boolean trackApplicationLifecycleEvents; private final Boolean amplitudeIntegrationEnabled; private final Boolean mixpanelIntegrationEnabled; + private final Boolean appsFlyerIntegrationEnabled; private final Boolean debug; - public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents, Boolean amplitudeIntegrationEnabled, Boolean mixpanelntegrationEnabled, Boolean debug) { + public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents, Boolean amplitudeIntegrationEnabled, Boolean mixpanelntegrationEnabled, Boolean appsFlyerIntegrationEnabled, Boolean debug) { this.writeKey = writeKey; this.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; this.amplitudeIntegrationEnabled = amplitudeIntegrationEnabled; this.mixpanelIntegrationEnabled = mixpanelntegrationEnabled; + this.appsFlyerIntegrationEnabled = appsFlyerIntegrationEnabled; this.debug = debug; } @@ -35,6 +37,10 @@ public Boolean isMixpanelIntegrationEnabled() { return mixpanelIntegrationEnabled; } + public Boolean isAppsFlyerIntegrationEnabled() { + return appsFlyerIntegrationEnabled; + } + public Boolean getDebug() { return debug; } @@ -44,8 +50,9 @@ static FlutterSegmentOptions create(Bundle bundle) { Boolean trackApplicationLifecycleEvents = bundle.getBoolean("com.claimsforce.segment.TRACK_APPLICATION_LIFECYCLE_EVENTS"); Boolean isAmplitudeIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_AMPLITUDE_INTEGRATION", false); Boolean isMixpanelIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_MIXPANEL_INTEGRATION", false); + Boolean isAppsFlyerIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_APPSFLYER_INTEGRATION", false); Boolean debug = bundle.getBoolean("com.claimsforce.segment.DEBUG", false); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, debug); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, isAppsFlyerIntegrationEnabled, debug); } static FlutterSegmentOptions create(HashMap options) { @@ -53,8 +60,9 @@ static FlutterSegmentOptions create(HashMap options) { Boolean trackApplicationLifecycleEvents = (Boolean) options.get("trackApplicationLifecycleEvents"); Boolean isAmplitudeIntegrationEnabled = orFalse((Boolean) options.get("amplitudeIntegrationEnabled")); Boolean isMixpanelIntegrationEnabled = orFalse((Boolean) options.get("mixpanelIntegrationEnabled")); + Boolean isAppsFlyerIntegrationEnabled = orFalse((Boolean) options.get("appsFlyerIntegrationEnabled")); Boolean debug = orFalse((Boolean) options.get("debug")); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, debug); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, isAppsFlyerIntegrationEnabled, debug); } private static Boolean orFalse(Boolean value) { diff --git a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java index 2944f381..af7c5e0f 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java @@ -16,6 +16,7 @@ import com.segment.analytics.integrations.BasePayload; import com.segment.analytics.android.integrations.amplitude.AmplitudeIntegration; import com.segment.analytics.android.integrations.mixpanel.MixpanelIntegration; +import com.segment.analytics.android.integrations.appsflyer.AppsflyerIntegration; import static com.segment.analytics.Analytics.LogLevel; import java.util.LinkedHashMap; @@ -90,6 +91,9 @@ private void setupChannels(FlutterSegmentOptions options) { if (options.isMixpanelIntegrationEnabled()) { analyticsBuilder.use(MixpanelIntegration.FACTORY); } + if (options.isAppsFlyerIntegrationEnabled()) { + analyticsBuilder.use(AppsflyerIntegration.FACTORY); + } // Here we build a middleware that just appends data to the current context // using the [deepMerge] strategy. diff --git a/ios/Classes/FlutterSegmentPlugin.m b/ios/Classes/FlutterSegmentPlugin.m index d31d07b0..d2d62e46 100644 --- a/ios/Classes/FlutterSegmentPlugin.m +++ b/ios/Classes/FlutterSegmentPlugin.m @@ -4,6 +4,7 @@ #import #import #import +#import "SEGAppsFlyerIntegrationFactory.h" @implementation FlutterSegmentPlugin // Contents to be appended to the context @@ -349,6 +350,7 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile { BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"com.claimsforce.segment.TRACK_APPLICATION_LIFECYCLE_EVENTS"] boolValue]; BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_AMPLITUDE_INTEGRATION"] boolValue]; BOOL isMixpanelIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_MIXPANEL_INTEGRATION"] boolValue]; + BOOL isAppsFlyerIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_APPSFLYER_INTEGRATION"] boolValue]; if(!writeKey) { return nil; } @@ -361,6 +363,9 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile { if (isMixpanelIntegrationEnabled) { [configuration use:[SEGMixpanelIntegrationFactory instance]]; } + if (isAppsFlyerIntegrationEnabled) { + [configuration use:[SEGAppsFlyerIntegrationFactory instance]]; + } return configuration; } @@ -370,6 +375,7 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict { BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"trackApplicationLifecycleEvents"] boolValue]; BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"amplitudeIntegrationEnabled"] boolValue]; BOOL isMixpanelIntegrationEnabled = [[dict objectForKey: @"mixpanelIntegrationEnabled"] boolValue]; + BOOL isAppsFlyerIntegrationEnabled = [[dict objectForKey: @"appsFlyerIntegrationEnabled"] boolValue]; SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey]; configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; @@ -379,6 +385,9 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict { if (isMixpanelIntegrationEnabled) { [configuration use:[SEGMixpanelIntegrationFactory instance]]; } + if (isAppsFlyerIntegrationEnabled) { + [configuration use:[SEGAppsFlyerIntegrationFactory instance]]; + } return configuration; } diff --git a/ios/flutter_segment.podspec b/ios/flutter_segment.podspec index f3c9a518..53dc2466 100644 --- a/ios/flutter_segment.podspec +++ b/ios/flutter_segment.podspec @@ -18,6 +18,7 @@ A new flutter plugin project. s.dependency 'Analytics', '4.1.6' s.dependency 'Segment-Amplitude', '3.3.2' s.dependency 'Segment-Mixpanel', '1.7.2' + s.dependency 'segment-appsflyer-ios', '6.8.0' s.ios.deployment_target = '11.0' # Added because Segment-Amplitude dependencies on iOS cause this error: diff --git a/lib/src/segment_config.dart b/lib/src/segment_config.dart index ae37b689..a6e9502a 100644 --- a/lib/src/segment_config.dart +++ b/lib/src/segment_config.dart @@ -4,6 +4,7 @@ class SegmentConfig { this.trackApplicationLifecycleEvents = false, this.amplitudeIntegrationEnabled = false, this.mixpanelIntegrationEnabled = false, + this.appsFlyerIntegrationEnabled = false, this.debug = false, }); @@ -11,6 +12,7 @@ class SegmentConfig { final bool trackApplicationLifecycleEvents; final bool amplitudeIntegrationEnabled; final bool mixpanelIntegrationEnabled; + final bool appsFlyerIntegrationEnabled; final bool debug; Map toMap() { @@ -19,6 +21,7 @@ class SegmentConfig { 'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents, 'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled, 'mixpanelIntegrationEnabled': mixpanelIntegrationEnabled, + 'appsFlyerIntegrationEnabled': appsFlyerIntegrationEnabled, 'debug': debug, }; } From 5089871a1f6273146b5e302ec3eee4d2c77f64db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Sza=C5=82ek?= Date: Mon, 5 May 2025 16:15:18 +0200 Subject: [PATCH 5/5] Support AGP 8 on Android --- android/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 17a6a98c..677bb996 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -32,6 +32,9 @@ android { lintOptions { disable 'InvalidPackage' } + if (project.android.hasProperty('namespace')) { + namespace 'com.example.flutter_segment' + } dependencies { implementation 'com.segment.analytics.android:analytics:4.10.4'