Android SDK
Introduction
Welcome to the developer documentation for the Kameleoon Android SDK! Our SDK gives you the possibility of running experiments and activating feature flags on native mobile Android applications. Integrating our SDK into your applications is relatively 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.
Our SDK is compatible with both Kotlin and Java.
Latest version of the Android SDK: 3.0.0 (changelog)
Getting started
This guide is designed to help you integrate our SDK in a few minutes and start running experiments in your Android applications. This tutorial will explain the setup of a simple A/B test to change the number of recommended products based on different variations.
Creating an experiment
First, you must create an experiment in the Kameleoon back-office so that our platform is aware of the new A/B test you're planning to implement on your side. Make sure that mobile application type is chosen as shown below:
Upon successful creation of the experiment, you will need to get its ID to use in the SDK as an argument to the triggerExperiment()
method.
Installing the SDK
Installing the Android client
dependencies {
implementation 'com.kameleoon:kameleoon-client-android:2.0.12'
}
dependencies {
implementation 'com.kameleoon:kameleoon-client-android:2.0.12'
}
You can install the Android SDK using by adding the following code into your build.gradle
file as shown in the example to the right.
Additional configuration
A .properties
configuration file can also be used to customize the SDK behavior. A sample configuration file can be obtained here. This file should be installed in the assets
directory of your application, and should be named exactly kameleoon-client.properties
. With the current version of the Android SDK, those are the available keys:
- client_id: a
client_id
is required field for authentication to the Kameleoon service. - client_secret: a
client_secret
is required field for authentication to the Kameleoon service. - actions_configuration_refresh_interval: this specifies the refresh interval, in minutes, of the configuration for experiments and feature flags (the active experiments and feature flags are fetched from the Kameleoon servers). An initial fetch is performed on the first application launch, and subsequent fetches are processed at the defined interval. It means that once you launch an experiment, pause it, or stop it the changes can take (at most) the duration of this interval to be propagated to the end-user Android devices. If not specified, the default interval is 60 minutes.
- environment: an option specifying which feature flag configuration will be used, by default each feature flag is split into production, staging, development. If not specified, will be set to default value of production. More information
Initializing the Kameleoon Client
import com.kameleoon.KameleoonClient;
import com.kameleoon.KameleoonClientFactory;
public class MyApplication extends Application
{
private KameleoonClient kameleoonClient;
@Override
public void onCreate() {
super.onCreate();
kameleoonClient = KameleoonClientFactory.create("a8st4f59bj", getApplicationContext());
}
public KameleoonClient getKameleoonClient() {
return kameleoonClient;
}
}
import com.kameleoon.KameleoonClient
import com.kameleoon.KameleoonClientFactory
class MyApplication : Application() {
var kameleoonClient: KameleoonClient? = null
private set
override fun onCreate() {
super.onCreate()
kameleoonClient = KameleoonClientFactory.create("a8st4f59bj", applicationContext)
}
}
After installing the SDK into your application and setting up a server-side experiment on Kameleoon's back-office, the next step is to create the Kameleoon client.
The code on the right gives a clear example. 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.
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.
Alternatively, we provide a helper callback to encapsulate the logic of experiment triggering and variation implementation. Which approach (isReady()
or callback) is best to use depends on your own preferences and on the exact use case at hand. As a rule of thumb, we recommend using isReady()
when it is expected that the SDK will indeed be ready for use. For instance, if you are running an experiment on some dialog that would be accessible only after a few seconds / minutes of navigation within the application. And we recommend using the callback when there is a high probability that the SDK is still in the process of initialization. For instance, an experiment that would take place at the application launch would be better treated with a callback that would make the application wait until either the SDK is ready or a specified timeout has expired.
It's the responsability of the developers to ensure the proper logic of their application code within the context of A/B testing via Kameleoon. A good practice is to always assume that the application user can be left out of the experiment because 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, which should be done in any case. The code samples in the next paragraph show examples of such an approach.
Triggering an experiment
Running an A/B experiment on your Android application means bucketing your users into several groups (one per variation). The SDK takes care of this bucketing (and the associated reporting) automatically.
Triggering an experiment by calling the triggerExperiment()
method will register a random variation for a given visitorCode. If this visitorCode is already associated with a variation (most likely the user had already been exposed to the experiment previously), then it will return the previous variation associated with a given experiment.
By analogy with the server-side SDKs and the global Kameleoon terminology, we will use the term visitorCode throughout this documentation. However, for mobile SDKs this does not really represent a visitor but rather the current user of the device.
Obtaining a unique visitorCode on a mobile application significantly differs from the server-side equivalents of the Android SDK, and is specific to your own implementation. You should almost always use the internal id for this user / account (database id, email...) as the visitorCode.
In any case, visitorCode uniqueness must be guaranteed on your end - the SDK cannot check it.
The length of visitorCode
is limited to 255 characters. Any excess characters will throw an exception.
The triggerExperiment()
method will quite often throw out exceptions. You should generally treat an exception as if the user was bucketed into the reference. Some possible common exceptions:
- Kameleoon client is not ready yet (discussed in previous section). This results in a KameleoonException.SDKNotReady exception.
- The experiment has not yet been launched on the Kameleoon platform (but the code implementing the experiment on the Android application's side is already deployed). This results in a KameleoonException.ExperimentConfigurationNotFound exception.
- You used a targeting segment for this experiment, and the user does not match this targeting segment. This results in a KameleoonException.NotTargeted exception.
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.kameleoon.KameleoonClient;
import com.kameleoon.KameleoonException;
public class MainActivity extends AppCompatActivity {
private MyApplication myApplication;
private TextView mTextMessage;
private int recommendedProductsNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myApplication = (MyApplication) getApplication();
KameleoonClient kameleoonClient = myApplication.getKameleoonClient();
int variationID;
if (kameleoonClient.isReady()) {
try {
String visitorCode = UUID.randomUUID().toString(); // usually, this would be the internal ID of the current user
variationID = kameleoonClient.triggerExperiment(visitorCode, 75253);
}
catch (KameleoonException.SDKNotReady | KameleoonException.ExperimentConfigurationNotFound | KameleoonException.NotTargeted |
KameleoonException.NotAllocated | KameleoonException.VisitorCodeNotValid exception) {
// The user will not be counted into the experiment, but should see the reference variation
variationID = 0;
}
}
else {
// The SDK is not ready, so the user is "out of the experiments". This is the same as if he was bucketed into the reference
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;
}
setContentView(R.layout.activity_main);
mTextMessage = (TextView) findViewById(R.id.message);
mTextMessage.setText("Number of recommended products displayed: " + recommendedProductsNumber + " products.");
}
}
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import com.kameleoon.KameleoonException.*
class MainActivity : AppCompatActivity() {
private lateinit var myApplication: MyApplication
private lateinit var mTextMessage: TextView
private var recommendedProductsNumber = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
myApplication = application as MyApplication
val kameleoonClient = myApplication.kameleoonClient!!
val variationID = if (kameleoonClient.isReady) {
try {
val visitorCode = UUID.randomUUID().toString() // usually, this would be the internal ID of the current user
kameleoonClient.triggerExperiment(visitorCode, 75253)
} catch (exception: Exception) {
when (exception) {
is SDKNotReady, is ExperimentConfigurationNotFound, is NotTargeted, is NotAllocated, is VisitorCodeNotValid -> 0
else -> throw exception
}
}
} else {
// The SDK is not ready, so the user is "out of the experiments". This is the same as if he was bucketed into the reference
0
}
when (variationID) {
0 -> {
//This is the default / reference number of products to display
recommendedProductsNumber = 5
}
148382 -> {
//We are changing number of recommended products for this variation to 10
recommendedProductsNumber = 10
}
187791 -> {
//We are changing number of recommended products for this variation to 8
recommendedProductsNumber = 8
}
}
setContentView(R.layout.activity_main)
mTextMessage = findViewById(R.id.message)
mTextMessage.text = "Number of recommended products displayed: $recommendedProductsNumber products."
}
}
We provide two code samples to illustrate the triggering of an experiment. The first one uses the isReady()
approach. It's a bit simpler.
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.kameleoon.KameleoonClient;
import com.kameleoon.KameleoonException;
import com.kameleoon.KameleoonReadyCallback;
public class MainActivity extends AppCompatActivity {
private TextView mTextMessage;
private KameleoonClient kameleoonClient;
private MyApplication myApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myApplication = (MyApplication) getApplication();
kameleoonClient = myApplication.getKameleoonClient();
setContentView(R.layout.activity_main);
mTextMessage = (TextView) findViewById(R.id.message);
kameleoonClient.runWhenReady(new ExampleKameleoonCallback(), 1000);
}
private class ExampleKameleoonCallback implements KameleoonReadyCallback
{
private int variationID;
private int recommendedProductsNumber;
@Override
public void onReady() {
try {
String visitorCode = UUID.randomUUID().toString(); // usually, this would be the internal ID of this user
variationID = kameleoonClient.triggerExperiment(visitorCode, 75253);
} catch (KameleoonException.SDKNotReady | KameleoonException.ExperimentConfigurationNotFound | KameleoonException.NotTargeted |
KameleoonException.NotAllocated | KameleoonException.VisitorCodeNotValid exception ) {
// The user will not be counted into the experiment, but should see the reference variation
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;
}
applyVariation();
}
@Override
public void onTimeout() {
variationID = 0;
recommendedProductsNumber = 5;
applyVariation();
}
private void applyVariation()
{
mTextMessage.setText("Number of recommended products displayed: " + recommendedProductsNumber + " products.");
}
}
}
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import com.kameleoon.KameleoonClient
import com.kameleoon.KameleoonReadyCallback
import com.kameleoon.KameleoonException.*
class MainActivity : AppCompatActivity() {
private lateinit var mTextMessage: TextView
private lateinit var kameleoonClient: KameleoonClient
private lateinit var myApplication: MyApplication
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
myApplication = application as MyApplication
kameleoonClient = myApplication.kameleoonClient!!
setContentView(R.layout.activity_main)
mTextMessage = findViewById(R.id.message)
kameleoonClient.runWhenReady(ExampleKameleoonCallback(), 1000)
}
private inner class ExampleKameleoonCallback : KameleoonReadyCallback {
private var variationID = 0
private var recommendedProductsNumber = 0
override fun onReady() {
variationID = try {
val visitorCode = UUID.randomUUID().toString() // usually, this would be the internal ID of this user
kameleoonClient.triggerExperiment(visitorCode, 75253)
} catch (exception: Exception) {
when (exception) {
is SDKNotReady, is ExperimentConfigurationNotFound, is NotTargeted, is NotAllocated, is VisitorCodeNotValid -> 0
else -> throw exception
}
}
when (variationID) {
0 -> {
// This is the default / reference number of products to display
recommendedProductsNumber = 5
}
148382 -> {
// We are changing number of recommended products for this variation to 10
recommendedProductsNumber = 10
}
187791 -> {
// We are changing number of recommended products for this variation to 8
recommendedProductsNumber = 8
}
}
applyVariation()
}
override fun onTimeout() {
variationID = 0
recommendedProductsNumber = 5
applyVariation()
}
private fun applyVariation() {
mTextMessage!!.text = "Number of recommended products displayed: $recommendedProductsNumber products."
}
}
}
This is a second example with the callback runWhenReady()
approach. You need to implement code both in the onReady()
and onTimeout()
methods. Note that here we used a timeout of 1000 milliseconds.
Implementing variation code
private int recommendedProductsNumber;
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;
}
private val recommendedProductsNumber: Int
when (variationID) {
0 -> {
//This is the default / reference number of products to display
recommendedProductsNumber = 5
}
148382 -> {
//We are changing number of recommended products for this variation to 10
recommendedProductsNumber = 10
}
187791 -> {
//We are changing number of recommended products for this variation to 8
recommendedProductsNumber = 8
}
}
To execute different code paths depending on the variation assigned to the visitor, you will need the list of all the experiment's variation IDs. You can find these variation IDs (as well as the experiment ID) by opening the experiment in the back-office interface. By convention, the reference (original variation) always has an ID equal to 0.
Once you have the IDs of the different variations, you can implement a different action for each variation, and one of the code paths will be executed, based on the associated variationID for the current visitor. Generally, this can be done using a simple if / else or switch mechanism. In our example, we just change the number of recommended products with two different variations.
Tracking conversion
String visitorCode = UUID.randomUUID().toString();
int goalID = 83023;
kameleoonClient.trackConversion(visitorCode, goalID, 10f);
val visitorCode = UUID.randomUUID().toString()
val goalID = 83023
try {
kameleoonClient.trackConversion(visitorCode, goalID, 10f)
} catch (exception: VisitorCodeNotValid) {
}
After you are done with triggering an experiment, the next step is usually to start tracking conversions. This is done to measure performance characteristics according to the goals that make sense for your business.
For this purpose, use the trackConversion()
method of the SDK as shown in the example. You need to pass the visitorCode and goalID parameters so we can correctly track conversion for this particular user.
Obtaining results
Once your implementation is in place on the mobile app side (experiment triggering, variations handling, and conversion tracking), it is time to launch the experiment on the Kameleoon platform. You do this in the same way as for a front-end test. Basic operations such as starting, pausing and stopping the experiment work in exactly the same way.
After the experiment has been launched, the first results will be available on our standard results page in the back-office after a duration of 30 minutes. This is because (as is the case with front-end testing) visits are considered over after 30 minutes of inactivity. Inactivity in this context means the absence of calls sent to the Kameleoon back-end servers (such calls are made via triggerExperiment()
, trackConversion()
or flush()
methods).
Getting SDK configuration
Overview
When you update your experiment or feature flag configuration, the SDK can get it in two different ways. The first - polling - consists in retrieving the configuration at regular intervals. The second - streaming - is to retrieve the new configuration immediately.
Polling
This mode of obtaining the configuration is used by default. The SDK will send a request to Cloudflare CDN at regular intervals to retrieve the configuration. If you have not set an interval in the SDK configuration, the configuration in SDK will be refreshed every 60 minutes. It can be configured with actions_configuration_refresh_interval parameter.
Benefits:
- When intervals are moderately spaced, this way of updating configuration consumes nominal memory and network resources.
Streaming
This mode allows the SDK to automatically take into account the new configuration without delay. When turned on, Kameleoon SDK is notified of any changes to the configuration in real-time, thanks to server-sent events (SSE).
Benefits:
- Makes it possible to propagate and apply a new configuration in real-time.
- Reduce network traffic compared to polling at short intervals, as streaming does not require sending periodic requests. It opens the connection once and then keeps it permanently open and ready to receive data.
- The best option for mobile applications requiring real-time updates, as it minimizes battery drain and data usage.
If you rely on instant data updates (real-time), then streaming is for you. If you wish to activate this mode, please contact us.
Reference
This is a full reference documentation of the Android SDK.
If this is your first time working with the Android SDK, we strongly recommend you go over our Getting started tutorial
to integrate the SDK and start experimenting in a few minutes.
com.kameleoon.KameleoonClientFactory
create
kameleoonClient = KameleoonClientFactory.create(siteCode, getApplicationContext());
KameleoonConfiguration config = new KameleoonConfiguration.Builder()
.clientId("<clientId>")
.clientSecret("<clientSecret>")
.environment("staging")
.build();
kameleoonClient = KameleoonClientFactory.create(siteCode, config, getApplicationContext());
kameleoonClient = KameleoonClientFactory.create(siteCode, applicationContext)
val config = KameleoonConfiguration.Builder()
.clientId("<clientId>")
.clientSecret("<clientSecret>")
.build()
kameleoonClient = KameleoonClientFactory.create(siteCode, config, this)
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. If you pass config
parameter, SDK will use it else try to find configuration file and try to use it.
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. |
configuration | KameleoonConfiguration | Configuration SDK object which can be used instead of configuration file. |
context | android.content.Context | Context of the Android application. This field is mandatory. |
com.kameleoon.KameleoonClient
isReady
Boolean ready = kameleoonClient.isReady();
val 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 setup exception catching around the triggerExperiment()
method to look for the KameleoonException.SDKNotReady exception, or you could use the runWhenReady()
method with a callback as detailed in the next paragraph.
Return value
Type | Description | |
---|---|---|
boolean | Boolean representing the status of the SDK (properly initialized, or not yet ready to be used). |
runWhenReady
kameleoonClient.runWhenReady(new ExampleKameleoonCallback(), 1000);
private class ExampleKameleoonCallback implements KameleoonReadyCallback
{
private int variationID;
private int recommendedProductsNumber;
@Override
public void onReady() {
try {
String visitorCode = UUID.randomUUID().toString(); // usually, this would be the internal ID of this user
variationID = kameleoonClient.triggerExperiment(visitorCode, 75253);
} catch (KameleoonException.SDKNotReady | KameleoonException.ExperimentConfigurationNotFound | KameleoonException.NotTargeted |
KameleoonException.NotAllocated | KameleoonException.VisitorCodeNotValid exception ) {
// The user will not be counted into the experiment, but should see the reference variation
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;
}
applyVariation();
}
@Override
public void onTimeout() {
variationID = 0;
recommendedProductsNumber = 5;
applyVariation();
}
private void applyVariation()
{
mTextMessage.setText("Number of recommended products displayed: " + recommendedProductsNumber + " products.");
}
kameleoonClient.runWhenReady(ExampleKameleoonCallback(), 1000)
private inner class ExampleKameleoonCallback : KameleoonReadyCallback {
private var variationID = 0
private var recommendedProductsNumber = 0
override fun onReady() {
variationID = try {
val visitorCode = UUID.randomUUID().toString() // usually, this would be the internal ID of this user
kameleoonClient.triggerExperiment(visitorCode, 75253)
} catch (exception: Exception) {
when (exception) {
is SDKNotReady, is ExperimentConfigurationNotFound, is NotTargeted, is NotAllocated, is VisitorCodeNotValid -> 0
else -> throw exception
}
}
when (variationID) {
0 -> {
// This is the default / reference number of products to display
recommendedProductsNumber = 5
}
148382 -> {
// We are changing number of recommended products for this variation to 10
recommendedProductsNumber = 10
}
187791 -> {
// We are changing number of recommended products for this variation to 8
recommendedProductsNumber = 8
}
}
applyVariation()
}
override fun onTimeout() {
variationID = 0
recommendedProductsNumber = 5
applyVariation()
}
private fun applyVariation() {
mTextMessage!!.text = "Number of recommended products displayed: $recommendedProductsNumber products."
}
}
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 callback given as first argument to this method must be a member of a class implementing the KameleoonReadyCallback interface. Two methods must be implemented: onReady()
and onTimeout()
. The onReady()
method will be called once the Kameleoon client is ready, and should contain code triggering an experiment and implementing variations. The onTimeout()
method will be called if the specified timeout happens before the client is initialized. Usually it should contain code implementing the reference variation, as the user will be "out of the experiment" if a timeout takes place.
Arguments
Name | Type | Description |
---|---|---|
callback | KameleoonReadyCallback | 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
String visitorCode = UUID.randomUUID().toString();
int experimentID = 75253;
int variationID;
try {
variationID = kameleoonClient.triggerExperiment(visitorCode, experimentID);
}
catch (KameleoonException.SDKNotReady | KameleoonException.ExperimentConfigurationNotFound e) {
// The user will not be counted into the experiment, but should see the reference variation
variationID = 0;
}
catch (KameleoonException.NotTargeted e) {
// The user did not trigger the experiment, as the associated targeting segment conditions were not fulfilled. He should see the reference variation
variationID = 0;
}
catch (KameleoonException.NotAllocated e) {
// The user triggered the experiment, but did not activate it. Usually, this happens because the user has been associated with excluded traffic
variationID = 0;
}
catch (KameleoonException.VisitorCodeNotValid) {
// The visitor code is invalid (empty or longer than 255 characters)
variationID = 0;
}
catch (Exception e) {
// This is generic Exception handler which will handle all exceptions.
System.out.println("Exception occurred");
}
val visitorCode = UUID.randomUUID().toString()
val experimentID = 75253
var variationID: Int
try {
variationID = kameleoonClient.triggerExperiment(visitorCode, experimentID)
} catch (e: SDKNotReady) {
// Exception indicating that the SDK has not completed its initialization yet.
variationID = 0
} catch (e: ExperimentConfigurationNotFound) {
variationID = 0
} catch (e: 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
} catch (e: NotAllocated) {
// The user triggered the experiment, but did not activate it. Usually, this happens because the user has been associated with excluded traffic
variationID = 0
} catch (e: VisitorCodeNotValid) {
// The visitor code is invalid (empty or longer than 255 characters)
variationID = 0
} catch (e: Exception) {
// This is generic Exception handler which will handle all exceptions.
println("Exception occurred")
}
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 | String | ID of the experiment you want to expose to a user. This field is mandatory. |
Return value
Type | Description | |
---|---|---|
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.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). | |
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.ExperimentConfigurationNotFound | Exception indicating that the requested 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 and variation implementations are already deployed on the mobile app's side). |
isFeatureActive
String visitorCode = UUID.randomUUID().toString();
String featureKey = "new_checkout";
Boolean hasNewCheckout = false;
try {
hasNewCheckout = kameleoonClient.isFeatureActive(visitorCode, featureKey);
}
catch (KameleoonException.SDKNotReady e) {
// Exception indicating that the SDK has not completed its initialization yet.
}
catch (KameleoonException.NotTargeted e) {
// The user did not trigger the feature, as the associated targeting segment conditions were not fulfilled. The feature should be considered inactive
hasNewCheckout = false;
}
catch (KameleoonException.FeatureConfigurationNotFound e) {
// SDK not initialized or feature toggle not yet activated on Kameleoon's side - we consider the feature inactive
hasNewCheckout = false;
}
catch (KameleoonException.VisitorCodeNotValid e) {
// The visitor code is invalid (empty or longer than 255 characters)
hasNewCheckout = false;
}
catch (Exception e) {
// This is generic Exception handler which will handle all exceptions.
System.out.println("Exception occurred")
}
if (hasNewCheckout)
{
// Implement new checkout code here
}
val visitorCode = UUID.randomUUID().toString()
val featureKey = "new_checkout"
var hasNewCheckout = false
try {
hasNewCheckout = kameleoonClient.isFeatureActive(visitorCode, featureKey)
} catch (e: SDKNotReady) {
// Exception indicating that the SDK has not completed its initialization yet.
hasNewCheckout = false
} catch (e: NotTargeted) {
// The user did not trigger the feature, as the associated targeting segment conditions were not fulfilled. The feature should be considered inactive
hasNewCheckout = false
} catch (e: FeatureConfigurationNotFound) {
// SDK not initialized or feature toggle not yet activated on Kameleoon's side - we consider the feature inactive
hasNewCheckout = false
} catch (e: VisitorCodeNotValid) {
// The visitor code is invalid (empty or longer than 255 characters)
hasNewCheckout = false
} catch (e: Exception) {
// This is generic Exception handler which will handle all exceptions.
println("Exception occurred")
}
if (hasNewCheckout) {
// Implement new checkout code here
}
Previously named: activateFeature
- deprecated since SDK version 3.0.0
and will be removed in a future releases
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 | Unique key of the feature you want to expose to a user. This field is mandatory. |
Return value
Type | Description |
---|---|
Boolean | 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.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
KameleoonException.NotTargeted | Exception indicating that the current visitor / user did not trigger the required targeting conditions for this feature. The targeting conditions are defined via Kameleoon's segment builder. |
KameleoonException.FeatureConfigurationNotFound | 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). |
getFeatureVariationKey
String visitorCode = UUID.randomUUID().toString();
String featureKey = "new_checkout";
String variationKey = "";
try {
variationKey = kameleoonClient.GetFeatureVariationKey(visitorCode, featureKey);
} catch (KameleoonException.FeatureConfigurationNotFound e) {
// The error is happened, feature flag isn't found in current configuraiton
} catch (KameleoonException.VisitoCodeNotValid e) {
// The visitor code which you passed to the method is invalid and can't be accepted by SDK
}
switch (variationKey) {
case 'on':
//main variation key is selected for visitorCode
break;
case 'alternative_variation':
//alternative variation key
break;
default:
//default variation key
break;
}
val visitorCode = UUID.randomUUID().toString()
val featureKey = "new_checkout"
var variationKey = ""
try {
variationKey = kameleoonClient.GetFeatureVariationKey(visitorCode, featureKey)
} catch (e: KameleoonException.FeatureConfigurationNotFound) {
// The error is happened, feature flag isn't found in current configuraiton
} catch (e: KameleoonException.VisitoCodeNotValid) {
// The visitor code which you passed to the method is invalid and can't be accepted by SDK
}
when (variationKey) {
'on' -> {}
'alternative_variation' -> {}
else -> {}
}
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 |
---|---|
string | Variation key of the feature flag that is registered for a given visitorCode. |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.FeatureConfigurationNotFound | 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.randomUUID().toString();
String featureKey = "feature_key";
String variableKey = "var";
try {
var variableValue = kameleoonClient.getFeatureVariable(visitorCode, featureKey, variableKey);
// your custom code depending of variableValue
} catch (KameleoonException.FeatureConfigurationNotFound e) {
// The error is happened, feature flag isn't found in current configuraiton
} catch (KameleoonException.FeatureVariableNotFound e) {
// Requested variable not defined on Kameleoon's side
} catch (KameleoonException.VisitoCodeNotValid e) {
// The visitor code which you passed to the method is invalid and can't be accepted by SDK
}
val visitorCode = UUID.randomUUID().toString()
val featureKey = "new_checkout"
val variableKey = "var"
try {
val variableValue = kameleoonClient.getFeatureVariable(visitorCode, featureKey, variableKey)
// your custom code depending of variableValue
} catch (e: KameleoonException. FeatureConfigurationNotFound) {
// The error is happened, feature flag isn't found in current configuraiton
} catch (e: KameleoonException.FeatureVariableNotFound) {
// Requested variable not defined on Kameleoon's side
} catch (e: KameleoonException.VisitoCodeNotValid) {
// The visitor code which you passed to the method is invalid and can't be accepted by SDK
}
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. |
variableName | string | Name of the variable you want to get a value. This field is mandatory. |
Return value
Type | Description |
---|---|
object | Value of variable of variation that is registered for a given visitorCode for this feature flag. Possible types: bool, int, double, string, JObject, JArray |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.FeatureConfigurationNotFound | 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.FeatureVariableNotFound | 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
String visitorCode = UUID.randomUUID().toString();
int experimentID = 75253;
try {
int variationID = kameleoonClient.triggerExperiment(visitorCode, experimentID);
JSONObject jsonObject = kameleoonClient.getVariationAssociatedData(variationID);
String firstName = jsonObject.getString("firstName");
}
catch (KameleoonException.VariationConfigurationNotFound e) {
// The variation is not yet activated on Kameleoon's side, ie the associated experiment is not online
}
catch (Exception e) {
// This is generic Exception handler which will handle all exceptions.
System.out.println("Exception occurred");
}
val visitorCode = UUID.randomUUID().toString()
val experimentID = 75253
try {
val variationID = kameleoonClient.triggerExperiment(visitorCode, experimentID)
val jsonObject = kameleoonClient.getVariationAssociatedData(variationID)
val firstName = jsonObject.getString("firstName")
} catch (e: VariationConfigurationNotFound) {
// The variation is not yet activated on Kameleoon's side, ie the associated experiment is not online
} catch (e: Exception) {
// This is generic Exception handler which will handle all exceptions.
println("Exception occurred")
}
Previously named: obtainVariationAssociatedData
- deprecated since SDK version 3.0.0
and will be removed in a future releases
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 org.json.JSONObject
instance. It will throw an exception (KameleoonException.VariationConfigurationNotFound
) 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 |
---|---|
org.json.JSONObject | Data associated with this variationID. |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.VariationConfigurationNotFound | 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 = "myFeature";
String variableKey = "myVariable";
String data;
try {
data = (String) kameleoonClient.obtainFeatureVariable(featureKey, variableKey);
}
catch (KameleoonException.FeatureConfigurationNotFound 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");
}
val featureKey = "myFeature"
val variableKey = "myVariable"
val data: String
try {
data = kameleoonClient.obtainFeatureVariable(featureKey, variableKey) as String
} catch (e: FeatureConfigurationNotFound) {
// The feature is not yet activated on Kameleoon's side
} catch (e: Exception) {
// This is generic Exception handler which will handle all exceptions.
println("Exception occurred")
}
Deprecated since SDK version 3.0.0
and will be removed in a future releases.
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 a java.lang.Object
instance. Usually it should be casted to the expected type (the one defined on the web interface). It will throw an exception (KameleoonException.FeatureConfigurationNotFound
) if the requested feature has not been found in the internal configuration of the SDK.
Arguments
Name | Type | Description |
---|---|---|
featureKey | String | 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 |
---|---|
java.lang.Object | Data associated with this variable for this feature flag. This can be a java.lang.Number, java.lang.String, java.lang.Boolean or org.json.JSONObject (depending on the type defined on the web interface). |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.FeatureConfigurationNotFound | 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. |
getFeatureAllVariables
String featureKey = "myFeature";
try {
Map<String, Object> allVariables = kameleoonClient.getFeatureAllVariables(featureKey);
}
catch (KameleoonException.FeatureConfigurationNotFound 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");
}
val featureKey = "myFeature"
try {
val allVariables = kameleoonClient.getFeatureAllVariables(featureKey)
} catch (e: FeatureConfigurationNotFound) {
// The feature is not yet activated on Kameleoon's side
} catch (e: Exception) {
// This is generic Exception handler which will handle all exceptions.
println("Exception occurred")
}
Previously named: obtainFeatureAllVariables
- deprecated since SDK version 3.0.0
and will be removed in a future releases
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 one input parameter: featureKey. It will return the data with the Map<String, Object>
type, as defined on the web interface. It will throw an exception (KameleoonException.FeatureConfigurationNotFound
) 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. |
Return value
Type | Description |
---|---|
Map<String,Object> | Data associated with this feature flag. The values of can be a int, string, boolean or J (depending on the type defined on the web interface). |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.FeatureConfigurationNotFound | 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. |
trackConversion
String visitorCode = UUID.randomUUID().toString();
int goalID = 83023;
kameleoonClient.addData(
visitorCode,
new Data.Interest(2)
);
kameleoonClient.addData(visitorCode, new Data.Conversion(32, 0f, false));
kameleoonClient.trackConversion(visitorCode, goalID);
val visitorCode = UUID.randomUUID().toString()
val goalID = 83023
try {
kameleoonClient.addData(
visitorCode,
Data.Interest(2)
)
kameleoonClient.addData(visitorCode, Data.Conversion(32, 0f, false))
kameleoonClient.trackConversion(visitorCode, goalID)
} catch (exception: VisitorCodeNotValid) {
}
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 | float | Revenue of the conversion. This field is optional. |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.SDKNotReady | Exception indicating that the SDK has not completed its initialization yet. |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
addData
kameleoonClient.addData(
visitorCode,
new Data.Interest(0),
new Data.Custom(1, "some custom value")
);
kameleoonClient.addData(visitorCode, new Data.Conversion(32, 10f, false));
kameleoonClient.addData(
visitorCode,
Data.Interest(0),
CustomData(1, "some custom value")
)
kameleoonClient.addData(visitorCode, Data.Conversion(32, 10f, false))
kameleoonClient.trackConversion(visitorCode, goalID)
To associate data with the current user, we can use the addData()
method. This method requires the visitorCode as a first parameter, and then accepts several 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, all declared data is saved for further sending via the flush()
method described in the next paragraph. This reduces the number of server calls made, as data is usually grouped into a single server call triggered by the execution of flush()
.
The triggerExperiment()
and trackConversion()
methods also send out previously associated data, just like the flush()
method.
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
dataTypes | Data | Custom data types which may be passed separated by a comma. |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.SDKNotReady | Exception indicating that the SDK has not completed its initialization yet. |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
flush
String visitorCode = UUID.randomUUID().toString();
kameleoonClient.addData(visitorCode, Data.Browser.CHROME);
kameleoonClient.addData(
visitorCode,
new Data.PageView("http://url.com", "title", Array.asList(3)),
new Data.Interest(0)
);
kameleoonClient.addData(visitorCode, new Data.Conversion(32, 10f, false));
kameleoonClient.flush(visitorCode);
val visitorCode = UUID.randomUUID().toString()
kameleoonClient.addData(visitorCode, Data.Browser.CHROME)
kameleoonClient.addData(
visitorCode,
Data.PageView("http://url.com", "title", Array.asList(3)),
Data.Interest(0)
)
kameleoonClient.addData(visitorCode, Data.Conversion(32, 10f, false))
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 control exactly 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. |
Exceptions Thrown
Type | Description |
---|---|
KameleoonException.SDKNotReady | Exception indicating that the SDK has not completed its initialization yet. |
KameleoonException.VisitorCodeNotValid | Exception indicating that the provided visitor code is not valid (empty, or longer than 255 characters). |
getExperimentList
List<Integer> allExperimentListId = kameleoonClient.getExperimentList();
val allExperimentListId = client.getExperimentList()
Previously named: obtainExperimentList
- deprecated since SDK version 3.0.0
and will be removed in a future releases
Returns a list of experiment IDs currently available for the SDK
Return value
Type | Description |
---|---|
List<Integer> | List of experiment's IDs |
getExperimentListForVisitorCode
Boolean onlyActive = true
List<Integer> allExperimentIdForVisitorCode = kameleoonClient.getExperimentListForVisitorCode(visitorCode, onlyActive);
// onlyActive == true by default
List<Integer> allExperimentIdForVisitorCode = kameleoonClient.getExperimentListForVisitorCode(visitorCode);
val onlyActive = true
val allExperimentIdForVisitorCode = client.getExperimentListForVisitorCode(visitorCode, onlyActive);
val allExperimentIdForVisitorCode = client.getExperimentListForVisitorCode(visitorCode, onlyActive);
Previously named: obtainExperimentListForVisitorCode
- deprecated since SDK version 3.0.0
and will be removed in a future releases
This method takes two input parameters: visitorCode and onlyActive. If onlyActive
parameter is true
result contains only active experiments, otherwise it contains all targeted experiments to specific visitorCode
. Returns a list of experiment IDs currently available for specific visitorCode
according to the onlyActive
option
Arguments
Name | Type | Description |
---|---|---|
visitorCode | String | Unique identifier of the user. This field is mandatory. |
onlyActive | boolean | The value is true by default, result contains only active for the user experiments. Set false for fetching all targeted experiment IDs. This field is optional. |
Return value
Type | Description |
---|---|
List<Integer> | List of experiment IDs available for specific visitorCode according to the onlyActive option |
getFeatureList
List<String> allFeatureFlagListId = kameleoonClient.getFeatureList();
val allFeatureFlagListId = kameleoonClient.getFeatureList();
Previously named: obtainFeatureList
- deprecated since SDK version 3.0.0
and will be removed in a future releases
Returns a list of feature flag keys currently available for the SDK
Return value
Type | Description |
---|---|
List<String> | List of feature flag keys |
getActiveFeatureListForVisitorCode
List<String> listActiveFeatureFlags = kameleoonClient.getActiveFeatureListForVisitorCode(visitorCode);
val listActiveFeatureFlags = kameleoonClient.getActiveFeatureListForVisitorCode(visitorCode);
Previously named: obtainFeatureListForVisitorCode
- deprecated since SDK version 3.0.0
and will be removed in a future releases
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 |
---|---|
List<String> | List of active feature flag keys available for specific visitorCode |
getRemoteData
kameleoonClient.getRemoteData("test", new KameleoonDataCallback() {
@Override
public void onSuccess(JSONObject jsonObject) {
// on success receiving data
}
@Override
public void onFail(Exception exception) {
// on fail
}
});
Previously named: retrieveDataFromRemoteSource
- deprecated since SDK version 3.1.0
and will be removed in a future releases
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, and you must pass a callback as argument to the method.
Arguments
Name | Type | Description |
---|---|---|
key | String | The key that the data you try to get is associated with. This field is mandatory. |
callback | KameleoonDataCallback | The callback for processing received data. KameleoonDataCallback has two methods: onSuccess(JSONObject) and onFail(Exception) . This field is mandatory. |
Errors Thrown
Type | Description |
---|---|
IOException | Error indicating that the SDK isn't available to make network request to a server. |
JSONException | Error indicating that the retrieved data is not available for JSON parsing |
updateConfigurationHandler
kameleoonClient.updateConfigurationHandler(() -> {
// configuration 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 | KameleoonUpdateConfigurationHandler | The handler that will be called when the configuration is updated using a real-time configuration event. |
com.kameleoon.Data
Browser
kameleoonClient.addData(visitorCode, Data.Browser.CHROME);
Name | Type | Description |
---|---|---|
browser | enum | List of browsers: CHROME, INTERNET_EXPLORER, FIREFOX, SAFARI, OPERA, OTHER. This field is mandatory. |
PageView
kameleoonClient.addData(
visitorCode,
new Data.PageView("https://url.com", "title", Array.asList(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<Integer> | 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
kameleoonClient.addData(visitorCode, new Data.Conversion(32, 10f, false));
kameleoonClient.addData(visitorCode, Data.Conversion(32, 10f, false))
Name | Type | Description |
---|---|---|
goalID | int | ID of the goal. This field is mandatory. |
revenue | float | Conversion revenue. This field is optional. |
negative | boolean | Defines if the revenue is positive or negative. This field is optional. |
CustomData
kameleoonClient.addData(
visitorCode,
new Data.CustomData(1, "some custom value")
);
kameleoonClient.addData(
visitorCode,
new Data.CustomData(1, "first value", "second value")
);
kameleoonClient.addData(
visitorCode,
new Data.CustomData(1, new String[]{ "first value", "second value" })
);
kameleoonClient.addData(
visitorCode,
CustomData(1, "some custom value")
)
kameleoonClient.addData(
visitorCode,
CustomData(1, "first value", "second value")
)
kameleoonClient.addData(
visitorCode,
CustomData(1, arrayOf("first value", "second value"))
)
Name | Type | Description |
---|---|---|
index | int | Index / ID of the custom data to be stored. This field is mandatory. |
values | String... or String[] or List<String> | Value(s) of the custom data to be stored. This field is optional. |
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
kameleoonClient.addData(
visitorCode,
Data.Device.DESKTOP);
Name | Type | Description |
---|---|---|
device | Device | List of devices: PHONE, TABLET, DESKTOP. This field is mandatory. |