Varioqub UI SDK integration
The Varioqub UI SDK provides a simple way to add and manage interactive widgets via Varioqub experiments.
Step 1. Adding dependencies
To use widgets, add the following two modules:
// The core Varioqub SDK
implementation "com.yandex.varioqub:config:0.9.0"
// The Varioqub UI module for displaying widgets
implementation "com.yandex.varioqub:ui:0.9.0"
Step 2. Adding Varioqub SDK to your app
If you've already set up the Varioqub SDK, skip to the next step. If not, follow these basic setup steps:
-
Create an adapter.
If you're already using Varioqub and have the
implementation "com.yandex.varioqub:appmetrica-adapter:0.9.0"dependency, useAppMetricaAdapter. Otherwise, create a null adapter. -
Recommendations
- When starting a new session, call the
activateConfig()method to get the stored flag values. - Run
fetchConfigin 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.
- When starting a new session, call the
Step 3. Setting up the Varioqub UI module for widgets
Creating the widget container
Add a container to your UI layout to hold the widget, such as FrameLayout, LinearLayout, or ConstraintLayout. We recommend setting the container's dimensions to fill the screen (match_parent for both width and height). This gives you the most flexibility for positioning the content.
Example:
<FrameLayout
android:id="@+id/popupContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Configuring deeplink handling
Configure deeplink handling in your AndroidManifest.xml file:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="demoapp" android:host="deeplink" />
</intent-filter>
Warning
This example uses the demoapp scheme and deeplink host, so it only processes deeplinks that match the demoapp://deeplink... format. Use your own scheme and host for your app.
Handling deeplinks and launching the widget
In your MainActivity, or wherever you want to display the widget, process the deeplink and launch the widget.
Code example:
import com.yandex.varioqub.ui.VarioqubUI
class MainActivity : AppCompatActivity() {
// Example code for the onCreate functions
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Handling the deeplink when creating an activity
intent.data?.let { uri ->
VarioqubUI.applyWidgetFromDeeplink(
"discount_widget", // Widget name from the Varioqub interface
binding.popupContainer, // Widget container
this,
uri,
"yadiscount", // Parameter prefix
true // Show logs
)
}
}
// Example code for the onNewIntent functions
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
// Handling the deeplink when receiving a new intent
intent.data?.let { uri ->
VarioqubUI.applyWidgetFromDeeplink(
"discount_widget",
binding.popupContainer,
this,
uri,
"yadiscount",
true
)
}
}
}
import com.yandex.varioqub.ui.VarioqubUI;
public class MainActivity extends AppCompatActivity {
// Example code for the onCreate functions
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Handling the deeplink when creating an activity
Uri uri = getIntent().getData();
if (uri != null) {
VarioqubUI.applyWidgetFromDeeplink(
"discount_widget", // Widget name from the Varioqub interface
binding.popupContainer, // Widget container
this,
uri,
"yadiscount", // Parameter prefix
true // Show logs
);
}
}
// Example code for the onNewIntent functions
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// Handling the deeplink when receiving a new intent
Uri uri = intent.getData();
if (uri != null) {
VarioqubUI.applyWidgetFromDeeplink(
"discount_widget",
binding.popupContainer,
this,
uri,
"yadiscount",
true
);
}
}
}