Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 411422b

Browse files
authored
Merge branch 'ubbop42:main' into main
2 parents c92e861 + 8f5b82d commit 411422b

File tree

6 files changed

+14
-21
lines changed

6 files changed

+14
-21
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ Currently [Optimizely](https://www.optimizely.com/) does not offer a dedicated f
88

99
## Usage
1010

11+
**You need to init and set up user before using an functions**
12+
1113
functions supported:
1214
[`isFeatureEnabled`](https://docs.developers.optimizely.com/full-stack/docs/is-feature-enabled-android)
1315
[`getAllFeatureVariables`](https://docs.developers.optimizely.com/full-stack/docs/get-all-feature-variables-android).
16+
[`getAllEnabledFeatures`](https://docs.developers.optimizely.com/full-stack/docs/get-all-feature-variables-android).
17+
[`activategetVariable`](https://docs.developers.optimizely.com/full-stack/docs/get-all-feature-variables-android).
1418
[`getVariable`](https://docs.developers.optimizely.com/full-stack/docs/get-all-feature-variables-android).
1519
[`trackEvent`](https://docs.developers.optimizely.com/full-stack/docs/get-all-feature-variables-android).
1620

1721
```dart
1822
import 'package:optimizely_dart/optimizely_dart.dart';
19-
...
2023
await OptimizelyPlugin.initOptimizelyManager('your_optimizely_sdk_key');
21-
bool featureEnabled = await OptimizelyPlugin.isFeatureEnabled('your_flag', 'some_user@xyz.com');
2224
...
23-
Map<String, dynamic> variables = await OptimizelyPlugin.getAllFeatureVariables(
24-
'your_flag_with_vars',
25-
'some_user@xyz.com',
26-
{'attribute_key': attribute_value},
27-
);
28-
String variable_value = variables['variable_name'];
25+
unawaited(OptimizelyPlugin().setUser(_personManager.person?.id, {'isLoggedIn':true}));
26+
...
27+
bool featureEnabled = await OptimizelyPlugin.isFeatureEnabled('your_flag', 'some_user@xyz.com');
2928
3029
var variation = await OptimizelyPlugin().getVariation('your_flag', 'some_user@xyz.com',{});
3130

android/src/main/kotlin/com/homexlabs/optimizely_dart/OptimizelyPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ class OptimizelyPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
8989
val variation = activateGetVariation(featureKey!!)
9090
result.success(variation)
9191
}
92-
"getvariation" -> {
92+
"getVariation"-> {
9393
val featureKey = call.argument<String>("feature_key")
9494
val userId = call.argument<String>("user_id")
9595
val attributes = call.argument<MutableMap<String, Any>>("attributes")
9696
val variation = getVariation(featureKey!!, userId!!, attributes!!)
97-
result.success(variation)
97+
result.success(variation?.key)
9898
}
9999
"trackEvent" -> {
100100
val featureKey = call.argument<String>("feature_key")

example/lib/main.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class _MyAppState extends State<MyApp> {
5050
try {
5151
bool? featureEnabled = await optimizelyPlugin.isFeatureEnabled(
5252
'price_filter',
53-
'user@example.org',
54-
{'platform': platform},
5553
);
5654
priceFilterFlag = 'price_filter feature is $featureEnabled.';
5755
} on PlatformException catch (e) {
@@ -76,8 +74,6 @@ class _MyAppState extends State<MyApp> {
7674
try {
7775
variables = await optimizelyPlugin.getAllFeatureVariables(
7876
'price_filter',
79-
'user@example.org',
80-
{'platform': platform},
8177
);
8278
int? minPrice = variables['min_price'];
8379
minPriceVariable = "min_price variable is: ${minPrice.toString()}.";

ios/Classes/OptimizelyPlugin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// Support project import fallback if the generated compatibility header
66
// is not copied when this plugin is created as a library.
77
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
8-
#import "optimizely_plugin-Swift.h"
8+
#import "OptimizelyPlugin.h"
99
#endif
1010

1111
@implementation OptimizelyPlugin
1212
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
13-
[SwiftOptimizelyPlugin registerWithRegistrar:registrar];
13+
[OptimizelyPlugin registerWithRegistrar:registrar];
1414
}
1515
@end

ios/Classes/SwiftOptimizelyPlugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ enum InitResult {
66
case failure(Error)
77
}
88

9-
public class SwiftOptimizelyPlugin: NSObject, FlutterPlugin {
9+
public class OptimizelyPlugin: NSObject, FlutterPlugin {
1010

1111
typealias GetFeatureItems = (featureKey: String, userId: String, attributes: OptimizelyAttributes?, eventTags: OptimizelyEventTags?)
1212
var client: OptimizelyClient?
@@ -17,7 +17,7 @@ public class SwiftOptimizelyPlugin: NSObject, FlutterPlugin {
1717
name: "optimizely_plugin",
1818
binaryMessenger: registrar.messenger()
1919
)
20-
let instance = SwiftOptimizelyPlugin()
20+
let instance = OptimizelyPlugin()
2121
registrar.addMethodCallDelegate(instance, channel: channel)
2222
}
2323

lib/optimizely_dart.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class OptimizelyPlugin {
5353
return Map<String, dynamic>.from(featureVariables);
5454
}
5555

56-
//https://docs.developers.optimizely.com/full-stack/docs/run-a-b-tests
57-
//TODO: deprecate: use activateGetVariation
5856
Future<String?> getVariation(
5957
String featureKey,
6058
userID,
@@ -79,7 +77,7 @@ class OptimizelyPlugin {
7977
String experimentKey,
8078
) async {
8179
final variation =
82-
await _channel.invokeMethod('getAllFeatureVariables', <String, dynamic>{
80+
await _channel.invokeMethod('activateGetVariation', <String, dynamic>{
8381
'feature_key': experimentKey,
8482
});
8583
return variation;

0 commit comments

Comments
 (0)