Skip to content

Commit

Permalink
refactor: update Amplitude interfaces (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 authored Feb 13, 2024
1 parent 6b291d8 commit 3d4996a
Show file tree
Hide file tree
Showing 27 changed files with 1,042 additions and 458 deletions.
38 changes: 19 additions & 19 deletions example/lib/deviceid_sessionid.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'app_state.dart';
// import 'app_state.dart';

class DeviceIdSessionId extends StatefulWidget {
@override
Expand All @@ -16,29 +16,29 @@ class _DeviceIdSessionIdState extends State<DeviceIdSessionId> {
Text('Device Id', style: Theme.of(context).textTheme.headlineSmall),
],
),
Row(
children: [
FutureBuilder(
future: AppState.of(context).analytics.getDeviceId(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return Text(snapshot.data.toString());
},
),
],
),
// Row(
// children: [
// FutureBuilder(
// // future: AppState.of(context).analytics.getDeviceId(),
// builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
// return Text(snapshot.data.toString());
// },
// ),
// ],
// ),
Row(
children: [
Text('Session Id', style: Theme.of(context).textTheme.headlineSmall),
],
),
Row(children: [
FutureBuilder(
future: AppState.of(context).analytics.getSessionId(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return Text(snapshot.data.toString());
},
),
])
// Row(children: [
// FutureBuilder(
// // future: AppState.of(context).analytics.getSessionId(),
// builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
// return Text(snapshot.data.toString());
// },
// ),
// ])
],
);
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/event_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class _EventFormState extends State<EventForm> {

void onPress() {
AppState.of(context)
..analytics.logEvent(_controller.text)
// ..analytics.logEvent(_controller.text)
..setMessage('Event sent.');
}

Expand Down
4 changes: 2 additions & 2 deletions example/lib/flush_thresholds_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _FlushThresholdFormState extends State<FlushThresholdForm> {

if (eventUploadThresholdInput.text.isNotEmpty && value != null) {
AppState.of(context)
..analytics.setEventUploadThreshold(value)
// ..analytics.setEventUploadThreshold(value)
..setMessage('Event upload threshold set.');
}
}
Expand All @@ -29,7 +29,7 @@ class _FlushThresholdFormState extends State<FlushThresholdForm> {

if (eventUploadPeriodMillisInput.text.isNotEmpty && value != null) {
AppState.of(context)
..analytics.setEventUploadPeriodMillis(value)
// ..analytics.setEventUploadPeriodMillis(value)
..setMessage('Event upload period millis set.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/group_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class _GroupFormState extends State<GroupForm> {
void onPress() {
if (groupType.text.isNotEmpty && groupValue.text.isNotEmpty) {
AppState.of(context)
..analytics.setGroup(groupType.text, groupValue.text)
// ..analytics.setGroup(groupType.text, groupValue.text)
..setMessage('Group set.');
}
}
Expand Down
8 changes: 4 additions & 4 deletions example/lib/group_identify_form.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:amplitude_flutter/identify.dart';
// import 'package:amplitude_flutter/identify.dart';
import 'package:flutter/material.dart';

import 'app_state.dart';
Expand All @@ -14,11 +14,11 @@ class _GroupIdentifyFormState extends State<GroupIdentifyForm> {
groupValue.text.isNotEmpty &&
groupPropertyKey.text.isNotEmpty &&
groupPropertyValue.text.isNotEmpty) {
final Identify identify = Identify()
..set(groupPropertyKey.text, groupPropertyValue.text);
// final Identify identify = Identify()
// ..set(groupPropertyKey.text, groupPropertyValue.text);

AppState.of(context)
..analytics.groupIdentify(groupType.text, groupValue.text, identify)
// ..analytics.groupIdentify(groupType.text, groupValue.text, identify)
..setMessage('Group Identify sent.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/identify_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _IdentifyFormState extends State<IdentifyForm> {
}

AppState.of(context)
..analytics.identify(identify)
// ..analytics.identify(identify)
..setMessage('Identify sent.');
}

Expand Down
50 changes: 25 additions & 25 deletions example/lib/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@ class _MyAppState extends State<MyApp> {
void initState() {
super.initState();

analytics = Amplitude.getInstance(instanceName: "project");
analytics.setUseDynamicConfig(true);
analytics.setServerUrl("https://api2.amplitude.com");
analytics.init(widget.apiKey);
analytics.enableCoppaControl();
analytics.setUserId("test_user", startNewSession: true);
analytics.trackingSessionEvents(true);
analytics.setMinTimeBetweenSessionsMillis(5000);
analytics.setEventUploadThreshold(5);
analytics.setEventUploadPeriodMillis(30000);
analytics.setServerZone("US");
analytics.logEvent('MyApp startup',
eventProperties: {'event_prop_1': 10, 'event_prop_2': true});
analytics.logEvent('Out of Session Event', outOfSession: true);
analytics.setOptOut(true);
analytics.logEvent('Opt Out Event');
analytics.setOptOut(false);
// analytics = Amplitude.getInstance(instanceName: "project");
// analytics.setUseDynamicConfig(true);
// analytics.setServerUrl("https://api2.amplitude.com");
// analytics.init(widget.apiKey);
// analytics.enableCoppaControl();
// analytics.setUserId("test_user", startNewSession: true);
// analytics.trackingSessionEvents(true);
// analytics.setMinTimeBetweenSessionsMillis(5000);
// analytics.setEventUploadThreshold(5);
// analytics.setEventUploadPeriodMillis(30000);
// analytics.setServerZone("US");
// analytics.logEvent('MyApp startup',
// eventProperties: {'event_prop_1': 10, 'event_prop_2': true});
// analytics.logEvent('Out of Session Event', outOfSession: true);
// analytics.setOptOut(true);
// analytics.logEvent('Opt Out Event');
// analytics.setOptOut(false);

Map<String, dynamic> userProps = {
'date': '01.06.2020',
'name': 'Name',
'buildNumber': '1.1.1',
};
analytics.logRevenueAmount(21.9);
analytics.setUserProperties(userProps);
// Map<String, dynamic> userProps = {
// 'date': '01.06.2020',
// 'name': 'Name',
// 'buildNumber': '1.1.1',
// };
// analytics.logRevenueAmount(21.9);
// analytics.setUserProperties(userProps);
}

Future<void> _flushEvents() async {
await analytics.uploadEvents();
// await analytics.uploadEvents();

setMessage('Events flushed.');
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/regenerate_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RegenerateDeviceBtn extends StatefulWidget {
class _DeviceState extends State<RegenerateDeviceBtn> {
void onPress() {
AppState.of(context)
..analytics.regenerateDeviceId()
// ..analytics.regenerateDeviceId()
..setMessage('Regenerate DeviceId.');
}

Expand Down
16 changes: 8 additions & 8 deletions example/lib/revenue_form.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'app_state.dart';
// import 'app_state.dart';

class RevenueForm extends StatefulWidget {
@override
Expand All @@ -18,13 +18,13 @@ class _RevenueFormState extends State<RevenueForm> {
if (productId.text.isNotEmpty &&
double.tryParse(price.text) != null &&
int.tryParse(quantity.text) != null) {
AppState.of(context)
..analytics.logRevenue(
productId.text,
int.tryParse(quantity.text)!,
double.tryParse(price.text)!,
)
..setMessage('Revenue Sent.');
// AppState.of(context)
// // ..analytics.logRevenue(
// productId.text,
// int.tryParse(quantity.text)!,
// double.tryParse(price.text)!,
// )
// ..setMessage('Revenue Sent.');
}
}

Expand Down
12 changes: 6 additions & 6 deletions example/lib/user_id_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class _UserIdFormState extends State<UserIdForm> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Current User Id', style: Theme.of(context).textTheme.headlineSmall),
FutureBuilder(
future: AppState.of(context).analytics.getUserId(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return Text(snapshot.data.toString());
},
),
// FutureBuilder(
// // future: AppState.of(context).analytics.getUserId(),
// builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
// return Text(snapshot.data.toString());
// },
// ),
const SizedBox(height: 10),
Text('User Id', style: Theme.of(context).textTheme.headlineSmall),
const SizedBox(height: 10),
Expand Down
2 changes: 1 addition & 1 deletion generate_test_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ flutter test --coverage
genhtml coverage/lcov.info -o coverage/report

# Step 3: Open the HTML coverage report:
#open ./coverage/report/index.html
open ./coverage/report/index.html
Loading

0 comments on commit 3d4996a

Please sign in to comment.