From 8ada790b1413a706a3bd683229c9a418e864ac71 Mon Sep 17 00:00:00 2001 From: Maik Schmidt Date: Tue, 25 Jan 2022 14:24:46 +0100 Subject: [PATCH 1/6] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9a44417d..a8b0fb0c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# ⚠️ DEPRECATION NOTE ⚠️ +This project is not longer maintained from this repository. We moved it to our friends from [La Haus](https://github.com/la-haus). + +You can find the latest version in this [GitHub repository](https://github.com/la-haus/flutter-library-segment). + # Segment plugin [![Pub Version](https://img.shields.io/pub/v/flutter_segment)](https://pub.dev/packages/flutter_segment) [![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint) From 47c1d4b6b812dd84abce8429a2975dad2151d481 Mon Sep 17 00:00:00 2001 From: Arief Wijaya Date: Mon, 14 Mar 2022 15:09:55 +0700 Subject: [PATCH 2/6] Update README.md --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index e5fc0ae2..537c2cc4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ -# ⚠️ DEPRECATION NOTE ⚠️ -This project is not longer maintained from this repository. We moved it to our friends from [La Haus](https://github.com/la-haus). - -You can find the latest version in this [GitHub repository](https://github.com/la-haus/flutter-library-segment). - # Segment plugin [![Pub Version](https://img.shields.io/pub/v/flutter_segment)](https://pub.dev/packages/flutter_segment) [![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint) From 3c7ab9e113b1339c70481ec1fe6e2915e06468bd Mon Sep 17 00:00:00 2001 From: Arief Wijaya Date: Tue, 15 Mar 2022 08:57:44 +0700 Subject: [PATCH 3/6] Add Dynamic and Scalable Segment Integration --- .../FlutterSegmentOptions.java | 35 +++++++++++-------- .../flutter_segment/FlutterSegmentPlugin.java | 29 +++++++++------ example/lib/main.dart | 3 +- lib/src/segment_config.dart | 9 +++-- 4 files changed, 47 insertions(+), 29 deletions(-) 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 3b225b0d..7a43652c 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java @@ -3,18 +3,25 @@ import android.os.Bundle; import java.util.HashMap; +import java.util.ArrayList; // import the ArrayList class + public class FlutterSegmentOptions { private final String writeKey; private final Boolean trackApplicationLifecycleEvents; - private final Boolean amplitudeIntegrationEnabled; private final Boolean debug; + private final ArrayList integrationItems; + + //nullable arguments + public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents,Boolean debug) { + this(writeKey,trackApplicationLifecycleEvents,debug,new ArrayList()); + } - public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents, Boolean amplitudeIntegrationEnabled,Boolean debug) { + public FlutterSegmentOptions(String writeKey, Boolean trackApplicationLifecycleEvents, Boolean debug, ArrayList integrationItems) { this.writeKey = writeKey; this.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; - this.amplitudeIntegrationEnabled = amplitudeIntegrationEnabled; this.debug = debug; + this.integrationItems = integrationItems; } public String getWriteKey() { @@ -25,28 +32,28 @@ public Boolean getTrackApplicationLifecycleEvents() { return trackApplicationLifecycleEvents; } - public Boolean isAmplitudeIntegrationEnabled() { - return amplitudeIntegrationEnabled; + public ArrayList getIntegrationItems() { + return integrationItems; } public Boolean getDebug() { return debug; } - 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 debug = bundle.getBoolean("com.claimsforce.segment.DEBUG", false); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, debug); - } + // 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 debug = bundle.getBoolean("com.claimsforce.segment.DEBUG", false); + // return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, debug); + // } static FlutterSegmentOptions create(HashMap options) { String writeKey = (String) options.get("writeKey"); Boolean trackApplicationLifecycleEvents = (Boolean) options.get("trackApplicationLifecycleEvents"); - Boolean isAmplitudeIntegrationEnabled = orFalse((Boolean) options.get("amplitudeIntegrationEnabled")); Boolean debug = orFalse((Boolean) options.get("debug")); - return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, debug); + ArrayList integrationItems = (ArrayList) options.get("integrationItems"); + return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, debug,integrationItems); } 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 547e21e4..a58351ac 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java @@ -20,6 +20,7 @@ import java.util.LinkedHashMap; import java.util.HashMap; import java.util.Map; +import java.util.ArrayList; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; @@ -55,17 +56,17 @@ private void setupChannels(Context applicationContext, BinaryMessenger messenger // register the channel to receive calls methodChannel.setMethodCallHandler(this); - try { - ApplicationInfo ai = applicationContext.getPackageManager() - .getApplicationInfo(applicationContext.getPackageName(), PackageManager.GET_META_DATA); + // try { + // ApplicationInfo ai = applicationContext.getPackageManager() + // .getApplicationInfo(applicationContext.getPackageName(), PackageManager.GET_META_DATA); - Bundle bundle = ai.metaData; + // Bundle bundle = ai.metaData; - FlutterSegmentOptions options = FlutterSegmentOptions.create(bundle); - setupChannels(options); - } catch (Exception e) { - Log.e("FlutterSegment", e.getMessage()); - } + // FlutterSegmentOptions options = FlutterSegmentOptions.create(bundle); + // setupChannels(options); + // } catch (Exception e) { + // Log.e("FlutterSegment", e.getMessage()); + // } } private void setupChannels(FlutterSegmentOptions options) { @@ -83,8 +84,14 @@ private void setupChannels(FlutterSegmentOptions options) { analyticsBuilder.logLevel(LogLevel.DEBUG); } - if (options.isAmplitudeIntegrationEnabled()) { - analyticsBuilder.use(AmplitudeIntegration.FACTORY); + for (String item : options.getIntegrationItems()) { + switch(item){ + case "amplitude": + analyticsBuilder.use(AmplitudeIntegration.FACTORY); + break; + default: + // do nothing + } } // Here we build a middleware that just appends data to the current context diff --git a/example/lib/main.dart b/example/lib/main.dart index 8ffc3bbc..d554d40c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -12,6 +12,7 @@ void main() { options: SegmentConfig( writeKey: 'YOUR_WRITE_KEY_GOES_HERE', trackApplicationLifecycleEvents: false, + integrationItems: const [SegmentIntegrationItemType.amplitude], ), ); @@ -60,7 +61,7 @@ class MyApp extends StatelessWidget { child: const Text('TRACK ACTION WITH SEGMENT'), onPressed: () { Segment.track( - eventName: 'ButtonClicked', + eventName: 'DevTest ButtonClicked', properties: { 'foo': 'bar', 'number': 1337, diff --git a/lib/src/segment_config.dart b/lib/src/segment_config.dart index 906cda69..5c9688cd 100644 --- a/lib/src/segment_config.dart +++ b/lib/src/segment_config.dart @@ -1,22 +1,25 @@ +enum SegmentIntegrationItemType { amplitude, unknown } + class SegmentConfig { SegmentConfig({ required this.writeKey, this.trackApplicationLifecycleEvents = false, - this.amplitudeIntegrationEnabled = false, this.debug = false, + this.integrationItems, }); final String writeKey; final bool trackApplicationLifecycleEvents; - final bool amplitudeIntegrationEnabled; + final List? integrationItems; final bool debug; Map toMap() { return { 'writeKey': writeKey, 'trackApplicationLifecycleEvents': trackApplicationLifecycleEvents, - 'amplitudeIntegrationEnabled': amplitudeIntegrationEnabled, 'debug': debug, + 'integrationItems': + integrationItems?.map((e) => e.toString().split(".").last).toList(), }; } } From b2ea9fc20e471288d97c6e894e909429332660af Mon Sep 17 00:00:00 2001 From: Arief Wijaya Date: Tue, 15 Mar 2022 13:08:39 +0700 Subject: [PATCH 4/6] improve implementation of integration on ios --- example/ios/Runner/Info.plist | 4 ---- ios/Classes/FlutterSegmentPlugin.m | 38 ++++++++---------------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index 5c1e3be0..58d6eb97 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -39,10 +39,6 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - com.claimsforce.segment.WRITE_KEY - YOUR_WRITE_KEY_GOES_HERE - com.claimsforce.segment.TRACK_APPLICATION_LIFECYCLE_EVENTS - UIViewControllerBasedStatusBarAppearance diff --git a/ios/Classes/FlutterSegmentPlugin.m b/ios/Classes/FlutterSegmentPlugin.m index b5aea645..45ce8165 100644 --- a/ios/Classes/FlutterSegmentPlugin.m +++ b/ios/Classes/FlutterSegmentPlugin.m @@ -15,12 +15,6 @@ + (void)registerWithRegistrar:(NSObject*)registrar { binaryMessenger:[registrar messenger]]; FlutterSegmentPlugin* instance = [[FlutterSegmentPlugin alloc] init]; - SEGAnalyticsConfiguration *configuration = [FlutterSegmentPlugin createConfigFromFile]; - if(configuration) { - [instance setup:configuration]; - wasSetupFromFile = YES; - } - [registrar addMethodCallDelegate:instance channel:channel]; } @@ -341,34 +335,22 @@ - (void)debug:(FlutterMethodCall*)call result:(FlutterResult)result { } } -+ (SEGAnalyticsConfiguration*)createConfigFromFile { - NSString *path = [[NSBundle mainBundle] pathForResource: @"Info" ofType: @"plist"]; - NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path]; - 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]; - if(!writeKey) { - return nil; - } - SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey]; - configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; - - if (isAmplitudeIntegrationEnabled) { - [configuration use:[SEGAmplitudeIntegrationFactory instance]]; - } - - return configuration; -} - + (SEGAnalyticsConfiguration*)createConfigFromDict:(NSDictionary*) dict { NSString *writeKey = [dict objectForKey: @"writeKey"]; BOOL trackApplicationLifecycleEvents = [[dict objectForKey: @"trackApplicationLifecycleEvents"] boolValue]; - BOOL isAmplitudeIntegrationEnabled = [[dict objectForKey: @"amplitudeIntegrationEnabled"] boolValue]; + NSArray *integrationItems = [dict objectForKey: @"integrationItems"]; SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:writeKey]; configuration.trackApplicationLifecycleEvents = trackApplicationLifecycleEvents; - if (isAmplitudeIntegrationEnabled) { - [configuration use:[SEGAmplitudeIntegrationFactory instance]]; + for (NSString* o in integrationItems) + { + ((void (^)())@{ + @"amplitude" : ^{ + [configuration use:[SEGAmplitudeIntegrationFactory instance]]; + }, + }[o] ?: ^{ + //Do Nothing + })(); } return configuration; From 5e539bfc81615bef533a16200640fe796eea045e Mon Sep 17 00:00:00 2001 From: Arief Wijaya Date: Tue, 15 Mar 2022 13:10:17 +0700 Subject: [PATCH 5/6] remove unused implementation --- .../flutter_segment/FlutterSegmentOptions.java | 8 -------- .../flutter_segment/FlutterSegmentPlugin.java | 12 ------------ example/android/app/src/main/AndroidManifest.xml | 15 --------------- 3 files changed, 35 deletions(-) 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 7a43652c..b3f1581e 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentOptions.java @@ -40,14 +40,6 @@ public Boolean getDebug() { return debug; } - // 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 debug = bundle.getBoolean("com.claimsforce.segment.DEBUG", false); - // return new FlutterSegmentOptions(writeKey, trackApplicationLifecycleEvents, isAmplitudeIntegrationEnabled, debug); - // } - static FlutterSegmentOptions create(HashMap options) { String writeKey = (String) options.get("writeKey"); Boolean trackApplicationLifecycleEvents = (Boolean) options.get("trackApplicationLifecycleEvents"); 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 a58351ac..a3c0bbde 100644 --- a/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java +++ b/android/src/main/java/com/example/flutter_segment/FlutterSegmentPlugin.java @@ -55,18 +55,6 @@ private void setupChannels(Context applicationContext, BinaryMessenger messenger methodChannel = new MethodChannel(messenger, "flutter_segment"); // register the channel to receive calls methodChannel.setMethodCallHandler(this); - - // try { - // ApplicationInfo ai = applicationContext.getPackageManager() - // .getApplicationInfo(applicationContext.getPackageName(), PackageManager.GET_META_DATA); - - // Bundle bundle = ai.metaData; - - // FlutterSegmentOptions options = FlutterSegmentOptions.create(bundle); - // setupChannels(options); - // } catch (Exception e) { - // Log.e("FlutterSegment", e.getMessage()); - // } } private void setupChannels(FlutterSegmentOptions options) { diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index b1b4bff1..8a3c8987 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -31,20 +31,5 @@ - - - - - From e72d3231717ee98964273f73b7cf9b307d58c551 Mon Sep 17 00:00:00 2001 From: Arief Wijaya Date: Tue, 15 Mar 2022 13:19:26 +0700 Subject: [PATCH 6/6] update documentations --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 537c2cc4..99cc4590 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,13 @@ Setup your Android, iOS and/or web sources as described at Segment.com and gener Set your Segment write key and change the automatic event tracking (only for Android and iOS) on if you wish the library to take care of it for you. Remember that the application lifecycle events won't have any special context set for you by the time it is initialized. +### Integration Item List +| Item | Supported | Enum Name | +|------------------|---|---| +| `Amplitude` | YES | `SegmentIntegrationItemType.amplitude` | + +You can tell the plugin tu use any integration item by insert them in `integrationItems` in `SegmentConfig`. + ### Via Dart Code ```dart void main() { @@ -106,14 +113,17 @@ void main() { options: SegmentConfig( writeKey: 'YOUR_WRITE_KEY_GOES_HERE', trackApplicationLifecycleEvents: false, - amplitudeIntegrationEnabled: false, + //Insert any plugins you want to use here, + //See `SegmentIntegrationItemType` enumeration + integrationItems: const [SegmentIntegrationItemType.amplitude], debug: false, ), ); } ``` -### Android _(Deprecated*)_ + +### Android _(Deprecated* & Removed)_ ```xml @@ -128,7 +138,7 @@ void main() { ``` -### iOS _(Deprecated*)_ +### iOS _(Deprecated* & Removed)_ ```xml