diff --git a/android/build.gradle b/android/build.gradle index 17947028..69dc22a0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,6 @@ buildscript { repositories { google() mavenCentral() - } dependencies { @@ -37,9 +36,11 @@ android { implementation 'com.segment.analytics.android:analytics:4.10.4' implementation 'com.segment.analytics.android.integrations:amplitude:3.1.0' implementation 'com.appsflyer:segment-android-integration:6.5.2' + implementation 'com.segment.analytics.android.integrations:firebase:2.3.3@aar' } } dependencies { testImplementation 'junit:junit:4.13.2' -} \ No newline at end of file +} + 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 2c0975d9..49d3af13 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java @@ -9,6 +9,7 @@ public class FlutterSegmentOptions { private final Boolean trackApplicationLifecycleEvents; private final Boolean amplitudeIntegrationEnabled; private final Boolean appsflyerIntegrationEnabled; + private final Boolean firebaseIntegrationEnabled; private final Boolean debug; public FlutterSegmentOptions( @@ -16,12 +17,14 @@ public FlutterSegmentOptions( Boolean trackApplicationLifecycleEvents, Boolean amplitudeIntegrationEnabled, Boolean appsflyerIntegrationEnabled, + Boolean firebaseIntegrationEnabled, Boolean debug ) { this.writeKey = writeKey; this.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; this.amplitudeIntegrationEnabled = amplitudeIntegrationEnabled; this.appsflyerIntegrationEnabled = appsflyerIntegrationEnabled; + this.firebaseIntegrationEnabled = firebaseIntegrationEnabled; this.debug = debug; } @@ -41,6 +44,10 @@ public Boolean isAppsflyerIntegrationEnabled() { return appsflyerIntegrationEnabled; } + public Boolean isFirebaseIntegrationEnabled() { + return firebaseIntegrationEnabled; + } + public Boolean getDebug() { return debug; } @@ -50,8 +57,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 isAppsflyerIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_APPSFLYER_INTEGRATION", false); + Boolean isFirebaseIntegrationEnabled = bundle.getBoolean("com.claimsforce.segment.ENABLE_FIREBASE_INTEGRATION", false); Boolean debug = bundle.getBoolean("com.claimsforce.segment.DEBUG", false); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isAppsflyerIntegrationEnabled, debug); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isAppsflyerIntegrationEnabled, isFirebaseIntegrationEnabled, debug); } static FlutterSegmentOptions create(HashMap options) { @@ -59,8 +67,9 @@ static FlutterSegmentOptions create(HashMap options) { Boolean trackApplicationLifecycleEvents = (Boolean) options.get("trackApplicationLifecycleEvents"); Boolean isAmplitudeIntegrationEnabled = orFalse((Boolean) options.get("amplitudeIntegrationEnabled")); Boolean isAppsflyerIntegrationEnabled = orFalse((Boolean) options.get("appsflyerIntegrationEnabled")); + Boolean isFirebaseIntegrationEnabled = orFalse((Boolean) options.get("firebaseIntegrationEnabled")); Boolean debug = orFalse((Boolean) options.get("debug")); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isAppsflyerIntegrationEnabled, debug); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isAppsflyerIntegrationEnabled, isFirebaseIntegrationEnabled, 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 40b92236..ce996916 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java @@ -14,6 +14,7 @@ import com.segment.analytics.integrations.BasePayload; import com.segment.analytics.android.integrations.amplitude.AmplitudeIntegration; import com.segment.analytics.android.integrations.appsflyer.AppsflyerIntegration; +import com.segment.analytics.android.integrations.firebase.FirebaseIntegration; import static com.segment.analytics.Analytics.LogLevel; import androidx.annotation.NonNull; @@ -85,6 +86,10 @@ private void setupChannels(FlutterSegmentOptions options) { analyticsBuilder.use(AppsflyerIntegration.FACTORY); } + if (options.isFirebaseIntegrationEnabled()) { + analyticsBuilder.use(FirebaseIntegration.FACTORY); + } + // Here we build a middleware that just appends data to the current context // using the [deepMerge] strategy. analyticsBuilder.useSourceMiddleware( diff --git a/ios/Classes/FlutterSegmentPlugin.m b/ios/Classes/FlutterSegmentPlugin.m index f3be03b0..f2e03105 100644 --- a/ios/Classes/FlutterSegmentPlugin.m +++ b/ios/Classes/FlutterSegmentPlugin.m @@ -4,6 +4,7 @@ #import #import #import +#import @implementation FlutterSegmentPlugin // Contents to be appended to the context @@ -353,6 +354,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 isFirebaseIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_FIREBASE_INTEGRATION"] boolValue]; if(!writeKey) { return nil; } @@ -363,6 +365,10 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile { [configuration use:[SEGAmplitudeIntegrationFactory instance]]; } + if (isFirebaseIntegrationEnabled) { + [configuration use:[SEGFirebaseIntegrationFactory instance]]; + } + return configuration; } @@ -371,6 +377,7 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict { BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"trackApplicationLifecycleEvents"] boolValue]; BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"amplitudeIntegrationEnabled"] boolValue]; BOOL isAppsflyerIntegrationEnabled = [[dict objectForKey: @"appsflyerIntegrationEnabled"] boolValue]; + BOOL isFirebaseIntegrationEnabled = [[dict objectForKey: @"firebaseIntegrationEnabled"] boolValue]; SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey]; configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; @@ -382,6 +389,10 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict { [configuration use:[SEGAppsFlyerIntegrationFactory instance]]; } + if (isFirebaseIntegrationEnabled) { + [configuration use:[SEGFirebaseIntegrationFactory instance]]; + } + return configuration; } diff --git a/ios/flutter_segment.podspec b/ios/flutter_segment.podspec index cfa64ede..bbb4205d 100644 --- a/ios/flutter_segment.podspec +++ b/ios/flutter_segment.podspec @@ -20,6 +20,7 @@ Library to let Flutter apps use Segment.io s.dependency 'Analytics', '4.1.6' s.dependency 'Segment-Amplitude', '3.3.2' s.dependency 'segment-appsflyer-ios', '6.8.0' + s.dependency 'Segment-Firebase', '2.7.11' 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 6dbdd660..261f9c35 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.appsflyerIntegrationEnabled = false, + this.firebaseIntegrationEnabled = false, this.debug = false, }); @@ -11,6 +12,7 @@ class SegmentConfig { final bool trackApplicationLifecycleEvents; final bool amplitudeIntegrationEnabled; final bool appsflyerIntegrationEnabled; + final bool firebaseIntegrationEnabled; final bool debug; Map toMap() { @@ -19,6 +21,7 @@ class SegmentConfig { 'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents, 'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled, 'appsflyerIntegrationEnabled': appsflyerIntegrationEnabled, + 'firebaseIntegrationEnabled': firebaseIntegrationEnabled, 'debug': debug, }; }