Skip to content

Commit

Permalink
Initial commit of Segment Provider lib
Browse files Browse the repository at this point in the history
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
claude committed Mar 8, 2023
1 parent 4e5e157 commit 5cb0587
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 31 deletions.
50 changes: 50 additions & 0 deletions lib/flutter_app_analytics_segment_provider.dart
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));
}
}
7 changes: 0 additions & 7 deletions lib/flutter_lib_jumpstart.dart

This file was deleted.

20 changes: 8 additions & 12 deletions pubspec.yaml
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
8 changes: 8 additions & 0 deletions test/flutter_app_analytics_segmen_provider_test.dart
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 -', () {});
}
12 changes: 0 additions & 12 deletions test/flutter_lib_jumpstart_test.dart

This file was deleted.

0 comments on commit 5cb0587

Please sign in to comment.