Flutter SDK
Welcome to the developer documentation for the Kameleoon Flutter SDK! Our SDK gives you the possibility of running experiments and activating feature flags on all platforms targeted by the Flutter application framework. Integrating our SDK into your applications is easy, and its footprint (in terms of memory and network usage) is low.
You can refer to the SDK reference
to check out all possible features of the SDK. Also make sure you check out our Getting started tutorial
which we have prepared to walk you through the installation and implementation.
Latest version of the Flutter SDK: 2.0.2 (changelog).
Getting started
This guide is designed to help you integrate our SDK in a few minutes and start running experiments in your Flutter applications. This tutorial will explain the setup of a simple A/B test to change the number of recommended products based on different variations.
Install the Flutter client
To install the Kameleoon Flutter client, declare a dependency on your pubspec.yaml
file:
kameleoon_client_flutter: ^2.0.0
Initialize the Kameleoon Client
After installing the SDK into your application and setting up an server-side experiment in the Kameleoon app, the next step is to create the Kameleoon client.
A Client is a singleton object that acts as a bridge between your application and the Kameleoon platform. It includes all the methods and properties you will need to run an experiment.
import 'package:kameleoon_client_flutter/kameleoon_client_flutter.dart';
class _HomePage extends State<HomePage> {
KameleoonClient kameleoonClient
void initState() {
super.initState();
kameleoonClient? = KameleoonClientFactory.create("a8st4f59bj");
}
}
While executing the KameleoonClientFactory.create()
method initializes the client, on Android it is not immediately ready for use. This is because the current configuration of experiments and feature flags (along with their traffic repartition) has to be retrieved from a Kameleoon remote server. This requires network access, which is not always available. Until the Kameleoon client is fully ready, you should not try to run any other method in our SDK. Note that once the first configuration of experiments is fetched, it is then periodically refreshed, but even if the refresh fails for any reason, the Kameleoon client will still be ready and working (but on an outdated / previous configuration).
We provide the isReady()
method to check if the Kameleoon client initialization is finished.
As the application developer, it's your responsibility to ensure your code uses correct login within the context of A/B testing via Kameleoon. A best practice is to leave the user out of the experiment if the Kameleoon client is not yet ready. This is actually easy to do, because this corresponds to the implementation of the default / reference variation logic.
Reference
This is a full reference documentation of the Flutter SDK.
KameleoonClientFactory
create
// Default values: environment = "production", refreshIntervalMinutes = 60
final config = KameleoonConfiguration("clientId", "clientSecret");
kameleoonClient = KameleoonClientFactory.create(siteCode);
final config = KameleoonConfiguration("clientId", "clientSecret", "development", 30);
kameleoonClient = KameleoonClientFactory.create(siteCode);
The starting point for using the SDK is the initialization step. All interaction with the SDK is done through an object named KameleoonClient, therefore you need to create this object.
Arguments
Name | Type | Description |
---|---|---|
siteCode | String | Code of the website you want to run experiments on. This unique code id can be found in our platform's back-office. This field is mandatory. |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.CredentialsNotFound | Exception indicating that the requested credentials were not provided (either via the configuration file, or via parameters on the method). |
KameleoonClient
isReady
bool ready = kameleoonClient.isReady();
For mobile SDKs, the initialization of the Kameleoon Client is not immediate, as it needs to perform a server call to retrieve the current configuration for all active experiments. It is recommended to check if the SDK is ready by calling this method before triggering an experiment. Alternatively, you could use the runWhenReady()
method with a callback as detailed in the next paragraph.
Arguments
Name | Type | Description |
---|
Return value
Name | Type | Description |
---|---|---|
ready | bool | Boolean representing the status of the SDK (properly initialized, or not yet ready to be used). |
runWhenReady
kameleoonClient.runWhenReady(() async {
late int variationId;
late int recommendedProductsNumber;
try {
variationId = await kameleoonClient.triggerExperiment(mainApplication.getUserId(), 75253);
} on KameleoonException.SDKNotReady {
// The user will not be counted into the experiment, but should see the reference variation
variationId = 0;
} on KameleoonException.ExperimentNotFound {
variationId = 0;
} on KameleoonException.NotTargeted {
variationId = 0;
} on KameleoonException.NotAllocated {
variationId = 0;
} on PlatformException {
variationId = 0;
}
if (variationId == 0) {
// This is the default / reference number of products to display
recommendedProductsNumber = 5;
}
else if (variationId == 148382) {
// We are changing number of recommended products for this variation to 10
recommendedProductsNumber = 10;
}
else if (variationId == 187791) {
// We are changing number of recommended products for this variation to 8
recommendedProductsNumber = 8;
}
setState(() {
_recommendedProductsNumber = recommendedProductsNumber;
});
}, () async {
variationId = 0;
recommendedProductsNumber = 5;
setState(() {
_recommendedProductsNumber = recommendedProductsNumber;
});
}, 1000);
For mobile SDKs, the initialization of the Kameleoon Client is not immediate, as it needs to perform a server call to retrieve the current configuration for all active experiments. The runWhenReady()
method of the KameleoonClient class allows to pass a callback that will be executed as soon as the SDK is ready for use. It also allows the use of a timeout.
The first callback will be executed once the Kameleoon client is ready, and should contain code triggering an experiment and implementing variations. The second callback will be executed if the specified timeout happens before the client is initialized. Usually this case should implement the "reference" variation, as the user will be "out of the experiment" if a timeout takes place.
Arguments
Name | Type | Description |
---|---|---|
readyCallback | Function | Callback object. This field is mandatory. |
failCallback | Function | Callback object. This field is mandatory. |
timeout | int | Timeout (in milliseconds). This field is optional, if not provided, it will use the default value of 2000 milliseconds. |
triggerExperiment
The triggerExperiment()
method will be deprecated as SDK and Hybrid type experiments are being merged with feature experimentation in September 2023. Use feature experimentation methods instead.
String visitorCode = Uuid().v4();
int experimentId = 75253;
late int variationId;
try {
variationId = await kameleoonClient!.triggerExperiment(visitorCode, experimentId);
} on KameleoonException.SDKNotReady {
// Exception indicating that the SDK has not completed its initialization yet.
variationId = 0;
} on KameleoonException.ExperimentNotFound {
// The user will not be counted into the experiment, but should see the reference variation
variationId = 0;
} on KameleoonException.NotTargeted {
// The user did not trigger the experiment, as the associated targeting segment
// conditions were not fulfilled. He should see the reference variation.
variationId = 0;
} on KameleoonException.NotAllocated {
// The user triggered the experiment, but got into unallocated traffic.
// Usually, this happens because the user has been associated with excluded traffic
variationId = 0;
} on KameleoonException.VisitorCodeNotValid {
// The provided visitor code is not valid
variationId = 0;
} on PlatformException {
// This is generic Exception handler which will handle all exceptions.
print("Exception occured");
}
To trigger an experiment, call the triggerExperiment()
method of our SDK.
This method takes visitorCode and experimentId as mandatory arguments to register a variation for a given user. If such a user has never been associated with any variation, the SDK returns a randomly selected variation. In case a user with a given visitorCode is already registered with a variation, it will detect the previously registered variation and return the variationId.
You have to make sure that proper error handling is set up in your code as shown in the example to the right to catch potential exceptions.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
experimentId | int | ID of the experiment you want to expose to a user. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<int> | ID of the variation that is registered for the given visitorCode. By convention, the reference (original variation) always has an ID equal to 0. |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.SDKNotReady | Exception indicating that the SDK has not completed its initialization yet. |
KameleoonException.NotTargeted | Exception indicating that the current user did not trigger the required targeting conditions for this experiment. The targeting conditions are defined via Kameleoon's segment builder. |
KameleoonException.NotAllocated | Exception indicating that the current user triggered the experiment (met the targeting conditions), but did not activate it. The most common reason for that is that part of the traffic has been excluded from the experiment and should not be tracked. |
KameleoonException.ExperimentNotFound | Exception indicating that the request experiment ID has not been found in the internal configuration of the SDK. This is usually normal and means that the experiment has not yet been started on Kameleoon's side (but code triggering / implementing variations is already deployed on the mobile app's side). |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
isFeatureActive
String visitorCode = Uuid().v4();
String featureKey = "new_checkout";
bool hasNewCheckout = false;
try {
hasNewCheckout = await kameleoonClient.isFeatureActive(visitorCode, featureKey);
} on KameleoonException.SDKNotReady {
// Exception indicating that the SDK has not completed its initialization yet.
hasNewCheckout = false;
} on KameleoonException.FeatureNotFound {
// SDK not initialized or feature toggle not yet activated on Kameleoon's side - we consider the feature inactive
hasNewCheckout = false;
} on KameleoonException.VisitorCodeNotValid {
// The provided visitor code is not valid
variationId = 0;
} on PlatformException {
// This is generic Exception handler which will handle all exceptions.
print("Exception occured");
}
if (hasNewCheckout) {
// Implement new checkout code here
}
To activate a feature toggle, call the isFeatureActive()
method of our SDK.
This method takes a visitorCode and featureKey as mandatory arguments to check if the specified feature will be active for a given user.
If such a user has never been associated with this feature flag, the SDK returns a boolean value randomly (true if the user should have this feature or false if not). If a user with a given visitorCode is already registered with this feature flag, it will detect the previous featureFlag value.
You have to make sure that proper error handling is set up in your code as shown in the example to the right to catch potential exceptions.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
featureKey | String | Key of the feature you want to expose to a user. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<bool> | Value of the feature that is registered for a given visitorCode. |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.SDKNotReady | Exception indicating that the SDK has not completed its initialization yet. |
KameleoonException.FeatureNotFound | Exception indicating that the requested feature ID has not been found in the internal configuration of the SDK. This is usually normal and means that the feature flag has not yet been activated on Kameleoon's side (but code implementing the feature is already deployed on the web-application's side). |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
getFeatureVariationKey
String visitorCode = Uuid().v4();
String featureKey = "new_checkout";
String variationKey = "";
try {
variationKey = await kameleoonClient.getFeatureVariationKey(visitorCode, featureKey);
} on KameleoonException.SDKNotReady {
// Exception indicating that the SDK has not completed its initialization yet.
} on KameleoonException.FeatureNotFound {
// SDK not initialized or feature toggle not yet activated on Kameleoon's side - we consider the feature inactive
} on KameleoonException.VisitorCodeNotValid {
// The provided visitor code is not valid
} on PlatformException {
// This is generic Exception handler which will handle all exceptions.
print("Exception occured");
}
switch(variationKey) {
case 'on':
// Main variation key is selected for visitorCode
break;
case 'alternative_variation':
// Alternative variation key
break;
default:
// Default variation key
break;
}
To get feature variation key, call the getFeatureVariationKey()
method of our SDK.
This method takes a visitorCode and featureKey as mandatory arguments to get variation key for a given user.
If such a user has never been associated with this feature flag, the SDK returns a variation key randomly (according to the feature flag rules). If a user with a given visitorCode is already registered with this feature flag, it will detect the previous variation key value. If the user does not match any of the rules, the default value will be returned, which we can define in your customer's account.
You have to make sure that proper error handling is set up in your code as shown in the example to the right to catch potential exceptions.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
featureKey | String | Key of the feature you want to expose to a user. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<String> | Variation key of the feature flag that is registered for a given visitorCode. |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.FeatureNotFound | Exception indicating that the requested feature key has not been found in the internal configuration of the SDK. This is usually normal and means that the feature flag has not yet been activated on Kameleoon's side (but code implementing the feature is already deployed on the web-application's side). |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
getFeatureVariable
String visitorCode = Uuid().v4();
String featureKey = "feature_key";
String variableKey = "var"
try {
final variableValue = await kameleoonClient.getFeatureVariable(visitorCode, featureKey, variableKey);
} on KameleoonException.SDKNotReady {
// Exception indicating that the SDK has not completed its initialization yet.
} on KameleoonException.FeatureNotFound {
// SDK not initialized or feature toggle not yet activated on Kameleoon's side - we consider the feature inactive
} on KameleoonException.VariableNotFound {
// Requested variable not defined on Kameleoon's side
} on KameleoonException.VisitorCodeNotValid {
// The provided visitor code is not valid
} on PlatformException {
// This is generic Exception handler which will handle all exceptions.
print("Exception occured");
}
To get variable of variation key associated with a user, call the getFeatureVariable()
method of our SDK.
This method takes a visitorCode, featureKey and variableKey as mandatory arguments to get a variable of variation key for a given user.
If such a user has never been associated with this feature flag, the SDK returns a variable value of variation key randomly (according to the feature flag rules). If a user with a given visitorCode is already registered with this feature flag, it will detect the variable value for previous associated variation. If the user does not match any of the rules, the variable of default value will be returned.
You have to make sure that proper error handling is set up in your code as shown in the example to the right to catch potential exceptions.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
featureKey | String | Key of the feature you want to expose to a user. This field is mandatory. |
variableKey | String | Name of the variable you want to get a value. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<dynamic> | Value of variable of variation that is registered for a given visitorCode for this feature flag. Possible types: bool, int, double, string, List, Map |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.FeatureNotFound | Exception indicating that the requested feature key has not been found in the internal configuration of the SDK. This is usually normal and means that the feature flag has not yet been activated on Kameleoon's side (but code implementing the feature is already deployed on the web-application's side). |
KameleoonException.VariableNotFound | Exception indicating that the requested variable has not been found. Check that the variable's key matches the one in your code. |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
getVariationAssociatedData
The GetVariationAssociatedData()
method will be deprecated as SDK and Hybrid type experiments are being merged with feature experimentation in September 2023. Use feature experimentation methods instead.
String visitorCode = Uuid().v4();
int experimentId = 75253;
try {
final variationId = await kameleoonClient.triggerExperiment(visitorCode, experimentId);
final jsonObject = await kameleoonClient.getVariationAssociatedData(variationId);
final firstName = jsonObject!["firstName"];
} on KameleoonException.VariationNotFound {
// The variation is not yet activated on Kameleoon's side, ie the associated experiment is not online
} on PlatformException {
// This is generic Exception handler which will handle all exceptions.
print("Exception occured");
}
Previously named: obtainVariationAssociatedData
- deprecated since SDK version 2.0.0
and will be removed in a future release.
To retrieve JSON data associated with a variation, call the getVariationAssociatedData()
method of our SDK. The JSON data usually represents some metadata of the variation, and can be configured on our web application interface or via our Automation API.
This method takes the variationId as a parameter and will return the data as a JSON object. It will throw an exception (KameleoonException.VariationNotFound
) if the variation ID is wrong or corresponds to an experiment that is not yet online.
Arguments
Name | Type | Description |
---|---|---|
variationId | int | ID of the variation you want to obtain associated data for. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<dynamic> | Data associated with this variationId. |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.VariationNotFound | Exception indicating that the requested variation ID has not been found in the internal configuration of the SDK. This is usually normal and means that the variation's corresponding experiment has not yet been activated on Kameleoon's side. |
obtainFeatureVariable
String featureKey = "featureKey";
String variableKey = "variableKey";
late String? data;
try {
data = await kameleoonClient!.obtainFeatureVariable(featureKey, variableKey) as String?;
} on KameleoonException.FeatureNotFound {
// The feature is not yet activated on Kameleoon's side
} on KameleoonException.VariableNotFound {
// Requested variable not defined on Kameleoon's side
} on PlatformException {
// This is generic Exception handler which will handle all exceptions.
print("Exception occured");
}
Deprecated since SDK version 2.0.0
and will be removed in a future release
Please use getFeatureVariable instead.
To retrieve a feature variable, call the obtainFeatureVariable()
method of our SDK. A feature variable can be changed easily via our web application.
This method takes two input parameters: featureKey and variableKey. It will return the data as an Object
instance. Usually it should be casted to the expected type (the one defined on the web interface). It will throw an exception (KameleoonException.FeatureNotFound
) if the requested feature has not been found in the internal configuration of the SDK.
Arguments
Name | Type | Description |
---|---|---|
featureID or featureKey | int or String | ID or Key of the feature you want to obtain to a user. This field is mandatory. |
variableKey | String | Key of the variable. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<dynamic> | Data associated with this variable for this feature flag. This can be a int, double, bool, String, List or Map (depending on the type defined on the web interface). |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.FeatureNotFound | Exception indicating that the requested feature ID has not been found in the internal configuration of the SDK. This is usually normal and means that the feature flag has not yet been activated on Kameleoon's side. |
KameleoonException.VariableNotFound | Exception indicating that the requested variable has not been found. Check that the variable's key matches the one in your code. |
getFeatureAllVariables
String featureKey = "featureKey";
String variationKey = "variationKey";
try {
Map<String, dynamic> allVariables = await client.getFeatureAllVariables(featureKey, variationKey);
}
catch (KameleoonException.FeatureNotFound e) {
// The feature is not yet activated on Kameleoon's side
}
catch (Exception e) {
// This is generic Exception handler which will handle all exceptions.
System.out.println("Exception occurred");
}
To retrieve the all feature variables, call the getFeatureAllVariables()
method of our SDK. A feature variable can be changed easily via our web application.
This method takes two input parameters: featureKey and variationKey. It will return the data with the Future<Map<String, dynamic>>
type, as defined on the web interface. It will throw an exception (KameleoonException.FeatureNotFound
) if the requested feature has not been found in the internal configuration of the SDK.
Arguments
Name | Type | Description |
---|---|---|
featureKey | String | Identificator key of the feature you need to obtain. This field is mandatory. |
variationKey | String | The key of the variation you want to obtain. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<Map<String, dynamic>> | Data associated with this feature flag. The values of can be a int, double, bool, String, List or Map (depending on the type defined on the web interface). |
Exceptions thrown
Type | Description |
---|---|
KameleoonException.FeatureNotFound | Exception indicating that the requested feature has not been found in the internal configuration of the SDK. This is usually normal and means that the feature flag has not yet been activated on Kameleoon''s side. |
KameleoonException.VariationNotFound | Exception indicating that the requested variation ID has not been found in the internal configuration of the SDK. This is usually normal and means that the variation's corresponding experiment has not yet been activated on Kameleoon's side. |
trackConversion
String visitorCode = Uuid().v4();
int goalId = 83023;
kameleoonClient.trackConversion(visitorCode, goalId);
To track conversion, use the trackConversion()
method. This method requires visitorCode and goalId to track conversion on this particular goal. In addition, this method also accepts revenue as a third optional argument to track revenue. The visitorCode should be identical to the one that was used when triggering the experiment.
The trackConversion()
method doesn't return any value. This method is non-blocking as the server call is made asynchronously.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
goalId | int | ID of the goal. This field is mandatory. |
revenue | double | Revenue of the conversion. This field is optional. |
addData
await kameleoonClient.addData(visitorCode, [Device(Devices.PHONE), CustomData(1, "some custom value")]);
To associate various data with the current user, we can use the addData()
method. This method requires the visitorCode as a first parameter, and then accept list of additional parameters. Those additional parameters represent the various Data Types allowed in Kameleoon.
Note that the addData()
method doesn't return any value and doesn't interact with the Kameleoon back-end servers by itself. Instead, every data declared is saved for further sending via the flush()
method described in the next paragraph. This allows a minimal number of server calls to be made, as data are usually regrouped in a single server call triggered by the execution of flush()
.
The triggerExperiment()
and trackConversion()
methods also sends out previously associated data, exactly as the flush()
method.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
data | List<Data> | one or more values conforming to the Data protocol which may be passed separated by a comma. |
flush
String visitorCode = Uuid().v4();
await kameleoonClient.addData(visitorCode, Browser(Browsers.CHROME));
kameleoonClient.flush(visitorCode);
Data associated with the current user via addData()
method is not sent immediately to the server. It is stored and accumulated until it is sent automatically by the triggerExperiment()
or trackConversion()
methods, or manually by the flush()
method. This allows the developer to exactly control when the data is flushed to our servers. For instance, if you call the addData()
method a dozen times, it would be a waste of ressources to send data to the server after each addData()
invocation. Just call flush()
once at the end.
The flush()
method doesn't return any value. This method is non-blocking as the server call is made asynchronously.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
getExperimentList
The getExperimentList()
method will be deprecated as SDK and Hybrid type experiments are being merged with feature experimentation in September 2023. Use feature experimentation methods instead.
final allExperimentList = await kameleoonClient.getExperimentList()
final activeExperimentsForVisitor = await kameleoonClient.getExperimentList(visitorCode: visitorCode) //onlyAllocated == true
final allExperimentsForVisitor = await kameleoonClient.getExperimentList(visitorCode: visitorCode, onlyAllocated: false)
Returns a list of experiment IDs currently available for the SDK or a list of experiment IDs currently available for specific visitorCode
according to the onlyAllocated
option.
This method can takes two input parameters: visitorCode and onlyAllocated. If onlyAllocated
parameter is true
result contains only active experiments, otherwise it contains all targeted experiments for specific visitorCode
.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is optional. |
onlyAllocated | bool | The value is true by default, result contains only active for the visitor experiments. Set false for fetching all targeted experiment IDs. This field is optional. |
Return value
Type | Description |
---|---|
Future<List<int>> | List of all experiment's IDs or a list of experiment IDs available for specific visitorCode according to the onlyActive option. |
getFeatureList
final allFeatureFlagKeys = await kameleoonClient.getFeatureList();
Returns a list of feature flag keys currently available for the SDK
Return value
Type | Description |
---|---|
Future<List<String>> | List of feature flag keys |
getFeatureListActive
final listActiveFeatureFlags = await kameleoonClient.getActiveFeatureListForVisitorCode(visitorCode);
This method takes only input parameters: visitorCode. Result contains only active feature flags for a given visitor.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<List<String>> | List of active feature flag keys available for specific visitorCode |
getRemoteData
var data = await kameleoonClient.getRemoteData("test");
kameleoonClient.getRemoteData("test").then((value) => {
//operate with retrieveing data
});
Previously named: retrieveDataFromRemoteSource
- deprecated since SDK version 2.0.0
and will be removed in a future release.
The getRemoteData()
method allows you to retrieve data (according to a key passed as argument) for specified siteCode (specified in KameleoonClientFactory.create()
) stored on a remote Kameleoon server. Usually data will be stored on our remote servers via the use of our Data API. This method, along with the availability of our highly scalable servers for this purpose, provides a convenient way to quickly store massive amounts of data that can be later retrieved for each of your visitors / users.
Note that since a server call is required, this mechanism is asynchronous.
Arguments
Name | Type | Description |
---|---|---|
key | String | The key that the data you try to get is associated with. This field is mandatory. |
Return value
Type | Description |
---|---|
Future<dynamic> | Future with retrieving data for specific key |
updateConfigurationHandler
kameleoonClient.updateConfigurationHandler(() {
// Configuration was updated
});
The updateConfigurationHandler()
method allows you to handle the event when configuration has updated data. It takes one input parameter handler. The handler that will be called when the configuration is updated using a real-time configuration event.
Arguments
Name | Type | Description |
---|---|---|
handler | Function | The handler that will be called when the configuration is updated using a real-time configuration event. |
Data
CustomData
await kameleoonClient!.addData(visitorCode, [CustomData(1, "some custom value")]);
Name | Type | Description |
---|---|---|
index | int | Index / ID of the custom data to be stored. This field is mandatory. |
value | String | Value of the custom data to be stored. This field is mandatory. |
The index (ID) of the custom data is available on our Back-Office, in the Custom data configuration page. Be careful: this index starts at 0, so the first custom data you create for a given site would have the ID 0, not 1.
Device
await kameleoonClient.addData(visitorCode, [Device(Devices.PHONE)]);
Name | Type | Description |
---|---|---|
device | Devices | List of devices: PHONE, TABLET, DESKTOP. This field is mandatory. |
Browser
await kameleoonClient.addData(visitorCode, [Browser(Browsers.CHROME)]);
Name | Type | Description |
---|---|---|
browser | Browsers | List of browsers: CHROME, INTERNET_EXPLORER, FIREFOX, SAFARI, OPERA, OTHER. This field is mandatory. |
PageView
await kameleoonClient.addData(visitorCode, [PageView("https://url.com", "title", [3])]);
Name | Type | Description |
---|---|---|
url | String | URL of the page viewed. This field is mandatory. |
title | String | Title of the page viewed. This field is mandatory. |
referrers | List<int> | Referrers of viewed pages. This field is optional. |
The index (ID) of the referrer is available on our Back-Office, in the Acquisition channel configuration page. Be careful: this index starts at 0, so the first acquisition channel you create for a given site would have the ID 0, not 1.
https://help.kameleoon.com/create-acquisition-channel
Conversion
await kameleoonClient!.addData(visitorCode, [Conversion(32, 10, false)]);
Name | Type | Description |
---|---|---|
goalId | String | ID of the goal. This field is mandatory. |
revenue | double | Conversion revenue. This field is optional. |
negative | bool | Defines if the revenue is positive or negative. This field is optional. |