Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Integration #60

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ buildscript {
repositories {
google()
mavenCentral()

}

dependencies {
Expand Down Expand Up @@ -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'
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ 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(
String writeKey,
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;
}

Expand All @@ -41,6 +44,10 @@ public Boolean isAppsflyerIntegrationEnabled() {
return appsflyerIntegrationEnabled;
}

public Boolean isFirebaseIntegrationEnabled() {
return firebaseIntegrationEnabled;
}

public Boolean getDebug() {
return debug;
}
Expand All @@ -50,17 +57,19 @@ 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<String, Object> options) {
String writeKey = (String) options.get("writeKey");
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions ios/Classes/FlutterSegmentPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import <Segment/SEGContext.h>
#import <Segment/SEGMiddleware.h>
#import <Segment_Amplitude/SEGAmplitudeIntegrationFactory.h>
#import <Segment_Firebase/SEGFirebaseIntegrationFactory.h>

@implementation FlutterSegmentPlugin
// Contents to be appended to the context
Expand Down Expand Up @@ -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;
}
Expand All @@ -363,6 +365,10 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile {
[configuration use:[SEGAmplitudeIntegrationFactory instance]];
}

if (isFirebaseIntegrationEnabled) {
[configuration use:[SEGFirebaseIntegrationFactory instance]];
}

return configuration;
}

Expand All @@ -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;

Expand All @@ -382,6 +389,10 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict {
[configuration use:[SEGAppsFlyerIntegrationFactory instance]];
}

if (isFirebaseIntegrationEnabled) {
[configuration use:[SEGFirebaseIntegrationFactory instance]];
}

return configuration;
}

Expand Down
1 change: 1 addition & 0 deletions ios/flutter_segment.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions lib/src/segment_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ class SegmentConfig {
this.trackApplicationLifecycleEvents = false,
this.amplitudeIntegrationEnabled = false,
this.appsflyerIntegrationEnabled = false,
this.firebaseIntegrationEnabled = false,
this.debug = false,
});

final String writeKey;
final bool trackApplicationLifecycleEvents;
final bool amplitudeIntegrationEnabled;
final bool appsflyerIntegrationEnabled;
final bool firebaseIntegrationEnabled;
final bool debug;

Map<String, dynamic> toMap() {
Expand All @@ -19,6 +21,7 @@ class SegmentConfig {
'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents,
'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled,
'appsflyerIntegrationEnabled': appsflyerIntegrationEnabled,
'firebaseIntegrationEnabled': firebaseIntegrationEnabled,
'debug': debug,
};
}
Expand Down