-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of Segment Provider lib
This adds the SegmentProvider class. I didn't add any tests after struggling a git with mockito. After talking to Drew, he said he normally doesn't test these wrapper libs, although there is some additional logic this lib provides. I'll revisit this later.
- Loading branch information
Showing
5 changed files
with
66 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
library flutter_app_analytics_segment_provider; | ||
|
||
import 'package:flutter_app_analytics/flutter_app_analytics.dart'; | ||
import 'package:flutter_segment/flutter_segment.dart'; | ||
|
||
/// A Segment Provider for Flutter app analytics. | ||
class SegmentProvider implements AnalyticsProvider { | ||
final String _writeKey; | ||
final String? _userId; | ||
|
||
SegmentProvider( | ||
this._writeKey, | ||
this._userId, | ||
); | ||
|
||
initialize() async { | ||
await Segment.config( | ||
options: SegmentConfig( | ||
writeKey: _writeKey, | ||
trackApplicationLifecycleEvents: false, | ||
amplitudeIntegrationEnabled: false, | ||
debug: false, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Future<void> identify({ | ||
String? userId, | ||
Map<String, dynamic>? properties, | ||
}) async { | ||
if (userId != null && properties != null) { | ||
await Segment.identify(userId: _userId, traits: properties); | ||
} else if (userId != null) { | ||
await Segment.identify(userId: _userId); | ||
} else if (properties != null) { | ||
await Segment.identify(traits: properties); | ||
} | ||
} | ||
|
||
@override | ||
Future<void> trackEvent(AnalyticsEvent event) async { | ||
await Segment.track(eventName: event.name, properties: event.properties); | ||
} | ||
|
||
@override | ||
Future<void> trackEvents(List<AnalyticsEvent> events) async { | ||
await Future.forEach<AnalyticsEvent>(events, (event) => trackEvent(event)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
name: jumpstart_flutter_lib | ||
description: A new Flutter package project. | ||
name: flutter_app_analytics_segment_provider | ||
description: A new Segment provider for app analytics | ||
version: 0.0.1 | ||
homepage: | ||
|
||
environment: | ||
sdk: '>=2.19.1 <3.0.0' | ||
flutter: ">=1.17.0" | ||
flutter: '>=1.17.0' | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter_app_analytics: | ||
git: https://github.com/uptech/flutter_app_analytics.git | ||
flutter_segment: ^3.12.1 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
flutter_lints: ^2.0.0 | ||
|
||
# For information on the generic Dart part of this file, see the | ||
# following page: https://dart.dev/tools/pub/pubspec | ||
|
||
# For details regarding assets in packages, see | ||
# https://flutter.dev/assets-and-images/#from-packages | ||
# | ||
# An image asset can refer to one or more resolution-specific "variants", see | ||
# https://flutter.dev/assets-and-images/#resolution-aware | ||
mockito: ^5.3.2 | ||
build_runner: ^2.3.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:flutter_segment/flutter_segment.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
|
||
@GenerateMocks([Segment]) | ||
void main() { | ||
group('SegmentProvider -', () {}); | ||
} |
This file was deleted.
Oops, something went wrong.