Skip to content

Commit

Permalink
[SDK-826] : A/B testing example added (#67)
Browse files Browse the repository at this point in the history
* A/B testing example added

* typo fixes
  • Loading branch information
ijunaid authored Jun 1, 2022
1 parent 5857590 commit a453271
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
58 changes: 54 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import 'dart:convert';
import 'package:countly_flutter/countly_flutter.dart';
import 'package:countly_flutter/countly_config.dart';


final navigatorKey = GlobalKey<NavigatorState>();
/// This or a similar call needs to added to catch and report Dart Errors to Countly,
/// You need to run app inside a Zone
/// and provide the [Countly.recordDartError] callback for [onError()]
void main() {
runZonedGuarded<Future<void>>(() async {
runApp(MyApp());
runApp(MaterialApp(
home: MyApp(),
navigatorKey: navigatorKey, // Setting a global key for navigator
),);
}, Countly.recordDartError);
}

Expand Down Expand Up @@ -395,6 +400,45 @@ class _MyAppState extends State<MyApp> {
Countly.askForNotificationPermission();
}

void _showDialog(String alterText) {
showDialog(
context: navigatorKey.currentContext!,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Alert!!'),
content: Text(alterText),
actions: <Widget>[
ElevatedButton(
child: Text('OK'),
onPressed: () {
Navigator.of(navigatorKey.currentContext!).pop();
},
),
],
);
},
);
}

void getABTestingValues() {
Countly.remoteConfigUpdate((result) {
Countly.getRemoteConfigValueForKey('baloon', (result) {
String alertText = "Value for 'baloon' is : ${result.toString()}";
_showDialog(alertText);
print(alertText);
});
});
}
void eventForGoal_1() {
var event = {'key': 'eventForGoal_1', 'count': 1};
Countly.recordEvent(event);
}

void eventForGoal_2() {
var event = {'key': 'eventForGoal_2', 'count': 1};
Countly.recordEvent(event);
}

void remoteConfigUpdate() {
Countly.remoteConfigUpdate((result) {
print(result);
Expand Down Expand Up @@ -463,7 +507,7 @@ class _MyAppState extends State<MyApp> {
}

void changeDeviceIdWithoutMerge() {
Countly.changeDeviceId('123456', false);
Countly.changeDeviceId(makeid(), false);
}

void addCrashLog() {
Expand Down Expand Up @@ -775,8 +819,8 @@ class _MyAppState extends State<MyApp> {
MyButton(text: 'Timed event Sum Segment: Start / Stop', color: 'grey', onPressed: endEventWithSumSegment),
MyButton(text: "Record View: 'HomePage'", color: 'olive', onPressed: recordViewHome),
MyButton(text: "Record View: 'Dashboard'", color: 'olive', onPressed: recordViewDashboard),
MyButton(text: "Record Direct Attribution'", color: 'olive', onPressed: recordDirectAttribution),
MyButton(text: "Record Indirect Attribution'", color: 'olive', onPressed: recordIndirectAttribution),
MyButton(text: 'Record Direct Attribution', color: 'olive', onPressed: recordDirectAttribution),
MyButton(text: 'Record Indirect Attribution', color: 'olive', onPressed: recordIndirectAttribution),
MyButton(text: 'Send Users Data', color: 'teal', onPressed: setUserData),
MyButton(text: 'UserData.setProperty', color: 'teal', onPressed: setProperty),
MyButton(text: 'UserData.increment', color: 'teal', onPressed: increment),
Expand Down Expand Up @@ -812,6 +856,12 @@ class _MyAppState extends State<MyApp> {
MyButton(text: 'Remove Consent Push', color: 'blue', onPressed: removeConsentpush),
MyButton(text: 'Remove Consent starRating', color: 'blue', onPressed: removeConsentstarRating),
MyButton(text: 'Remove Consent Performance', color: 'blue', onPressed: removeConsentAPM),

Text("Section for A/B testing:", style: TextStyle(color: Colors.green), textAlign: TextAlign.center),
MyButton(text: 'Get AB testing values', color: 'green', onPressed: getABTestingValues),
MyButton(text: 'Record event for goal #1', color: 'green', onPressed: eventForGoal_1),
MyButton(text: 'Record event for goal #2', color: 'green', onPressed: eventForGoal_2),

MyButton(text: 'Countly.remoteConfigUpdate', color: 'purple', onPressed: remoteConfigUpdate),
MyButton(text: 'Countly.updateRemoteConfigForKeysOnly', color: 'purple', onPressed: updateRemoteConfigForKeysOnly),
MyButton(text: 'Countly.updateRemoteConfigExceptKeys', color: 'purple', onPressed: updateRemoteConfigExceptKeys),
Expand Down
3 changes: 3 additions & 0 deletions lib/countly_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class Countly {
if (config.manualSessionEnabled != null) {
_manualSessionControlEnabled = config.manualSessionEnabled!;
}
if (config.enableUnhandledCrashReporting != null) {
_enableCrashReportingFlag = config.enableUnhandledCrashReporting!;
}
_channel.setMethodCallHandler(_methodCallHandler);

List<dynamic> args = [];
Expand Down

0 comments on commit a453271

Please sign in to comment.