Skip to content
Draft
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
12 changes: 9 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ android {
lintOptions {
disable 'InvalidPackage'
}
if (project.android.hasProperty('namespace')) {
namespace 'com.example.flutter_segment'
}

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'
implementation 'com.appsflyer:segment-android-integration:6.5.2'
implementation 'com.android.installreferrer:installreferrer:2.1'
}
}

dependencies {
testImplementation 'junit:junit:4.12'
}
}
2 changes: 2 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter_segment">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ public class FlutterSegmentOptions {
private final String writeKey;
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 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;
}

Expand All @@ -29,6 +33,14 @@ public Boolean isAmplitudeIntegrationEnabled() {
return amplitudeIntegrationEnabled;
}

public Boolean isMixpanelIntegrationEnabled() {
return mixpanelIntegrationEnabled;
}

public Boolean isAppsFlyerIntegrationEnabled() {
return appsFlyerIntegrationEnabled;
}

public Boolean getDebug() {
return debug;
}
Expand All @@ -37,16 +49,20 @@ 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 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, debug);
return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, isAppsFlyerIntegrationEnabled, 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 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, debug);
return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, isMixpanelIntegrationEnabled, isAppsFlyerIntegrationEnabled, debug);
}

private static Boolean orFalse(Boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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 com.segment.analytics.android.integrations.appsflyer.AppsflyerIntegration;
import static com.segment.analytics.Analytics.LogLevel;

import java.util.LinkedHashMap;
Expand Down Expand Up @@ -86,6 +88,12 @@ private void setupChannels(FlutterSegmentOptions options) {
if (options.isAmplitudeIntegrationEnabled()) {
analyticsBuilder.use(AmplitudeIntegration.FACTORY);
}
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.
Expand Down
18 changes: 18 additions & 0 deletions ios/Classes/FlutterSegmentPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#import <Segment/SEGContext.h>
#import <Segment/SEGMiddleware.h>
#import <Segment_Amplitude/SEGAmplitudeIntegrationFactory.h>
#import <Segment_Mixpanel/SEGMixpanelIntegrationFactory.h>
#import "SEGAppsFlyerIntegrationFactory.h"

@implementation FlutterSegmentPlugin
// Contents to be appended to the context
Expand Down Expand Up @@ -347,6 +349,8 @@ + (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];
BOOL isAppsFlyerIntegrationEnabled = [[dict objectForKey: @"com.claimsforce.segment.ENABLE_APPSFLYER_INTEGRATION"] boolValue];
if(!writeKey) {
return nil;
}
Expand All @@ -356,6 +360,12 @@ + (SEGAnalyticsConfiguration*)createConfigFromFile {
if (isAmplitudeIntegrationEnabled) {
[configuration use:[SEGAmplitudeIntegrationFactory instance]];
}
if (isMixpanelIntegrationEnabled) {
[configuration use:[SEGMixpanelIntegrationFactory instance]];
}
if (isAppsFlyerIntegrationEnabled) {
[configuration use:[SEGAppsFlyerIntegrationFactory instance]];
}

return configuration;
}
Expand All @@ -364,12 +374,20 @@ + (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];
BOOL isAppsFlyerIntegrationEnabled = [[dict objectForKey: @"appsFlyerIntegrationEnabled"] boolValue];
SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey];
configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents;

if (isAmplitudeIntegrationEnabled) {
[configuration use:[SEGAmplitudeIntegrationFactory instance]];
}
if (isMixpanelIntegrationEnabled) {
[configuration use:[SEGMixpanelIntegrationFactory instance]];
}
if (isAppsFlyerIntegrationEnabled) {
[configuration use:[SEGAppsFlyerIntegrationFactory instance]];
}

return configuration;
}
Expand Down
2 changes: 2 additions & 0 deletions ios/flutter_segment.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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.dependency 'segment-appsflyer-ios', '6.8.0'
s.ios.deployment_target = '11.0'

# Added because Segment-Amplitude dependencies on iOS cause this error:
Expand Down
6 changes: 6 additions & 0 deletions lib/src/segment_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ class SegmentConfig {
required this.writeKey,
this.trackApplicationLifecycleEvents = false,
this.amplitudeIntegrationEnabled = false,
this.mixpanelIntegrationEnabled = false,
this.appsFlyerIntegrationEnabled = false,
this.debug = false,
});

final String writeKey;
final bool trackApplicationLifecycleEvents;
final bool amplitudeIntegrationEnabled;
final bool mixpanelIntegrationEnabled;
final bool appsFlyerIntegrationEnabled;
final bool debug;

Map<String, dynamic> toMap() {
return {
'writeKey': writeKey,
'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents,
'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled,
'mixpanelIntegrationEnabled': mixpanelIntegrationEnabled,
'appsFlyerIntegrationEnabled': appsFlyerIntegrationEnabled,
'debug': debug,
};
}
Expand Down