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

feat: add option to activate native integration with appsflyer #19

Merged
merged 4 commits into from
Apr 21, 2022
Merged
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
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.appsflyer:segment-android-integration:6.5.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ public class FlutterSegmentOptions {
private final String writeKey;
private final Boolean trackApplicationLifecycleEvents;
private final Boolean amplitudeIntegrationEnabled;
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 appsflyerIntegrationEnabled,
Boolean debug
) {
this.writeKey = writeKey;
this.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents;
this.amplitudeIntegrationEnabled = amplitudeIntegrationEnabled;
this.appsflyerIntegrationEnabled = appsflyerIntegrationEnabled;
this.debug = debug;
}

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

public Boolean isAppsflyerIntegrationEnabled() {
return appsflyerIntegrationEnabled;
}

public Boolean getDebug() {
return debug;
}
Expand All @@ -37,16 +49,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 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, 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 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, 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,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.appsflyer.AppsflyerIntegration;
import static com.segment.analytics.Analytics.LogLevel;

import java.util.LinkedHashMap;
Expand Down Expand Up @@ -87,6 +88,10 @@ private void setupChannels(FlutterSegmentOptions options) {
analyticsBuilder.use(AmplitudeIntegration.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.
analyticsBuilder.middleware(
Expand Down
3 changes: 1 addition & 2 deletions example/lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

// ignore: implementation_imports
danielgomezrico marked this conversation as resolved.
Show resolved Hide resolved
import 'package:flutter_segment/src/segment_web.dart';

// ignore: implementation_imports
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/FlutterSegmentPlugin.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "SEGAppsFlyerIntegrationFactory.h"
#import "FlutterSegmentPlugin.h"
#import <Segment/SEGAnalytics.h>
#import <Segment/SEGContext.h>
Expand Down Expand Up @@ -364,13 +365,18 @@ + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict {
NSString *writeKey = [dict objectForKey: @"writeKey"];
BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"trackApplicationLifecycleEvents"] boolValue];
BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"amplitudeIntegrationEnabled"] boolValue];
BOOL isAppsflyerIntegrationEnabled = [[dict objectForKey: @"appsflyerIntegrationEnabled"] boolValue];
SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey];
configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents;

if (isAmplitudeIntegrationEnabled) {
[configuration use:[SEGAmplitudeIntegrationFactory instance]];
}

if (isAppsflyerIntegrationEnabled) {
[configuration use:[SEGAppsFlyerIntegrationFactory 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 @@ -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-appsflyer-ios', '6.5.2'
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 @@ -3,19 +3,22 @@ class SegmentConfig {
required this.writeKey,
this.trackApplicationLifecycleEvents = false,
this.amplitudeIntegrationEnabled = false,
this.appsflyerIntegrationEnabled = false,
this.debug = false,
});

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

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