Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aar package should be preferred to not get resource not found errors:

implementation 'com.segment.analytics.android.integrations:firebase:2.3.3@aar'

please see: https://segment.com/docs/connections/destinations/catalog/firebase/#getting-started-on-android

Note: The Firebase SDK requires android resources which are available on aar packages. Use the aar package when adding the Segment-Firebase SDK.

}
}

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 @@ -350,6 +351,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 @@ -360,6 +362,10 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile {
[configuration use:[SEGAmplitudeIntegrationFactory instance]];
}

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

return configuration;
}

Expand All @@ -368,6 +374,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 @@ -379,6 +386,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 @@ -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-appsflyer-ios', '6.5.2'
s.dependency 'Segment-Firebase', '2.7.10'
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