SDK integration
- General integration recommendations
- Step 1. Add the library to your project
- Step 2. Initialize the library
- Step 3. Set the default configuration using an XML file
- Step 4. Run a background update of the flag configuration
- Step 5. Activate the configuration
- Getting flags from the interface
- Obtaining the device ID to test the experiment
To use the Varioqub SDK, add and initialize the AppMetrica Android library. For more information on how to do this, see the AppMetrica SDK documentation.
App requirements:
-
Android version 5 or later.
-
Android Studio 2021 or later.
-
Make sure that your app's build file has the following values:
- minSdkVersion 21 or later.
- compileSdkVersion 31 or later.
General integration recommendations
-
When starting a new session, call the
activateConfig()
method to retrieve the stored flag values. -
Run
fetchConfig
in the background to export the new flag values from the server and activate them when the next session starts. -
We don't recommend calling the
activateConfig()
method mid-session because it can cause inconsistent app behavior.
Step 1. Add the library to your project
To integrate the Varioqub SDK, add the following dependencies to the module-level Gradle file of your app (usually app/build.gradle.kts or app/build.gradle):
dependencies {
implementation("com.yandex.varioqub:config:0.7.0")
implementation("com.yandex.varioqub:appmetrica-adapter:0.7.0")
implementation("io.appmetrica.analytics:analytics:7.10.0")
}
dependencies {
implementation 'com.yandex.varioqub:config:0.7.0'
implementation 'com.yandex.varioqub:appmetrica-adapter:0.7.0'
implementation 'io.appmetrica.analytics:analytics:7.10.0'
}
Step 2. Initialize the library
To initialize the library, use the init(settings: VarioqubSettings, adapter: VarioqubConfigAdapter, context: Context)
method. It takes the following parameters:
-
settings: VarioqubSettings
. Contains required and optional settings.In the settings, specify your project ID as
appmetrica.XXXXXX
, where XXXXXX is the app ID from the AppMetrica interface. For example,VarioqubSettings.Builder("appmetrica.1234567")
.Tip
You can get the application ID from the AppMetrica Settings page: copy it in General settings → Application ID.
You can also pass a list of custom parameters with
withClientFeature
. For example, you can pass a flag indicating if the user is subscribed to newsletters. -
adapter: VarioqubConfigAdapter
. Adapter for collecting statistics and sending them to an analytics system, such as AppMetrica. If you don't want to collect statistics, use a null adapter. -
context: Context
.
import com.yandex.varioqub.appmetricaadapter.AppMetricaAdapter
import com.yandex.varioqub.config.FetchError
import com.yandex.varioqub.config.OnFetchCompleteListener
import com.yandex.varioqub.config.Varioqub
import com.yandex.varioqub.config.VarioqubSettings
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
val settings = VarioqubSettings.Builder("appmetrica.1234567")
.withClientFeature("my_cool_feature", "true")
.build()
Varioqub.init(settings, AppMetricaAdapter(this), this)
}
}
import com.yandex.varioqub.appmetricaadapter.AppMetricaAdapter;
import com.yandex.varioqub.config.FetchError;
import com.yandex.varioqub.config.OnFetchCompleteListener;
import com.yandex.varioqub.config.Varioqub;
import com.yandex.varioqub.config.VarioqubSettings;
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
VarioqubSettings settings = new VarioqubSettings.Builder("appmetrica.1234567")
.withClientFeature("my_cool_feature", "true")
.build();
Varioqub.init(settings, new AppMetricaAdapter(this), this);
}
}
VarioqubSettings parameters
Contains required and optional settings:
-
VarioqubSettings.Builder("client_id")
: Builder with a project ID specified asappmetrica.XXXXXX
, where XXXXXX is the app ID from the AppMetrica interface. For example,VarioqubSettings.Builder("appmetrica.1234567")
.Tip
You can get the application ID from the AppMetrica Settings page: copy it in General settings → Application ID.
-
withClientFeature("myCoolFeature", "LovelyFeatureValue")
: Function containing a list of custom parameters. For example, you can pass a flag indicating if the user is subscribed to newsletters. -
withThrottleInterval(2)
: Limit on the frequency of config updates in seconds. This is only recommended for testing purposes. -
withUrl(url: String)
: Changes the URL for server responses. Only used for testing. -
withLogs()
: Enables internal logging. To help us diagnose your problem, please enable logging and attach the log file with a description of the problem when submitting your support request. -
withActivateEvent(enabled: Boolean)
: Sends an event when the flag configuration is activated. Event sending is enabled by default.
Single custom parameter
val settings = VarioqubSettings.Builder("appmetrica.1234567")
.withClientFeature("my_cool_feature", "true")
.withThrottleInterval(2)
.build()
Multiple custom parameters
val settings = VarioqubSettings.Builder("appmetrica.1234567")
.withClientFeature("my_cool_feature", "true")
.withClientFeature("my_best_feature", "false")
.withClientFeature("mode", "night")
.withThrottleInterval(2)
.build()
Single custom parameter
VarioqubSettings settings = new VarioqubSettings.Builder("appmetrica.1234567")
.withClientFeature("my_cool_feature", "true")
.withThrottleInterval(2)
.build();
Multiple custom parameters
VarioqubSettings settings = new VarioqubSettings.Builder("appmetrica.1234567")
.withClientFeature("my_cool_feature", "true")
.withClientFeature("my_best_feature", "false")
.withClientFeature("mode", "night")
.withThrottleInterval(2)
.build();
Step 3. Set the default configuration using an XML file
You can set up a default configuration to have your app use your preferred parameter values before it connects to a remotely configured server.
-
Download the XML configuration file from the Flag configuration page and save it to your app's
res/xml
folder. -
Pass the loaded XML configuration file using the
setDefaults(int)
method.KotlinJavaVarioqub.setDefaults(R.xml.ab_defaults)
Varioqub.setDefaults(R.xml.ab_defaults);
Note
The file name
ab_defaults.xml
is a placeholder used for demonstration purposes.
Step 4. Run a background update of the flag configuration
To use the most recent flag configuration from the interface, run a background configuration update using the fetchConfig
method.
Note
Each time you receive the latest version of the configuration (most often this occurs when starting a new session), you need to activate it using the activateConfig()
method.
Varioqub.fetchConfig(object : OnFetchCompleteListener {
override fun onSuccess() {
Log.i("VARIOQUB", "FETCH SUCCESS")
// you can use the device ID while testing the experiment
// to do this, specify it in the corresponding A/B experiments field
Log.i("VARIOQUB", Varioqub.getId())
}
override fun onError(message: String, error: FetchError) {
Log.i("VARIOQUB", "FETCH ERROR: $message")
}
})
Varioqub.fetchConfig(new OnFetchCompleteListener() {
@Override
public void onSuccess() {
Log.i("VARIOQUB", "FETCH SUCCESS");
// you can use the device ID while testing the experiment
// to do this, specify it in the corresponding A/B experiments field
Log.i("VARIOQUB", Varioqub.getId());
}
@Override
public void onError(String message, FetchError error) {
Log.i("VARIOQUB", "FETCH ERROR: " + message);
}
});
Step 5. Activate the configuration
Tip
Main use case:
Regularly download the configuration and activate it when the app is launched. That guarantees your flags won't change during user sessions. We recommend launching activation as soon as possible.
Activate the configuration using the activateConfig()
method.
Varioqub.activateConfig()
Varioqub.activateConfig();
Use the activateConfig()
method every time you want to activate a received/loaded configuration (for example, when starting a new session).
Getting flags from the interface
Flag values are retrieved and returned in the following order:
- Flag is present in the experiment.
- Flag is present in the loaded configuration.
- Flag is present in the default configuration.
Flag getters:
Varioqub.getString(key, default)
.
Code example:
val flag = Varioqub.getString("flag", "defaultValue")
Log.i("VARIOQUB", flag)
String flag = Varioqub.getString("flag", "defaultValue");
Log.i("VARIOQUB", flag);
Obtaining the device ID to test the experiment
To get the device ID, use the Varioqub.getId()
method:
Log.i("VARIOQUB", Varioqub.getId())
Log.i("VARIOQUB", Varioqub.getId());
Note
The Varioqub.getId()
method can return an empty response before the first successful fetchConfig
result.
To learn more about creating and testing experiments, see Creating an experiment.