SDK Integration
This document provides steps for integrating your Android app with Hackle via the Android Hackle SDK. SDK Integration is a must in order to use the functions provided by the Hackle SDK.
- Step 1: Add Dependencies
- Step 2: Initialize the SDK
- Step 3 : A/B test, Feature Flag
- Step 4 : Send customer event
Step 1: Add Dependencies
The SDK is distributed to mavenCentral.
If the settings below have already been added to build.gradle, you do not need to add them.
repositories {
mavenCentral()
}
Add SDK Dependencies
dependencies {
implementation 'io.hackle:hackle-android-sdk:2.16.0'
}
ProGuard / R8
If you are using ProGuard, R8, the obfuscation rules are automatically included in the aar artifact. If this is not the case, you should also include the rule below.
-keep class io.hackle.android.** { *; }
-keep class io.hackle.sdk.** { *; }
Step 2: Initialize the SDK
Once you have imported the dependencies, in order to start using the Hackle SDK you must initialize the SDK. During this step, we get the information needed for SDK integration from the Hackle Server and store it in the SDK. As this operation runs asynchronously, the callback action lets you know that the initialization is complete.
Initialize the SDK by passing the SDK key and callback to the HackleApp.initializeApp()
method.
The SDK key can be found in the SDK integration in the dashboard of Hackle service.
// Enter the SDK Key in the YOUR_APP_SDK_KEY.
HackleApp.initializeApp(getApplicationContext(), YOUR_APP_SDK_KEY, () -> {
// SDK ready to use.
});
// Enter the SDK Key in the YOUR_APP_SDK_KEY.
Hackle.initialize(applicationContext, YOUR_APP_SDK_KEY) {
// SDK ready to use.
}
SDK initialization should only occur once
The
HackleApp.initializeApp()
method must only be called once.
It is recommended to initialize the SDK in theonCreate()
method of theApplication
instance.
Recommended initialization method: initialize via loading screen
Instead of starting the app immediately, display a loading screen and initialize the SDK.
The callback then closes the loading screen and allows the user to start interacting with the app.
If you're using this method, it's a good idea to put a time limit on the loading screen.
After initialization, you can obtain the HackleApp instance through the code below.
HackleApp hackleApp = HackleApp.getInstance();
val hackleApp = Hackle.app
Add Settings
You can add additional settings in SDK initialization
HackleConfig config = HackleConfig.builder()
.exposureEventDedupIntervalMillis(1000)
.build();
HackleApp.initializeApp(getApplicationContext(), YOUR_APP_SDK_KEY, config, () -> {
// SDK ready to use.
});
val config = HackleConfig.builder()
.exposureEventDedupIntervalMillis(1000)
.build()
Hackle.initialize(applicationContext, YOUR_APP_SDK_KEY, config) {
// SDK ready to use.
}
Key | Function | Default Value | Supported Version |
---|---|---|---|
exposureEventDedupIntervalMillis | Removes consecutive exposure events for the same A/B test, feature flag from the same user Min value: 1000 (1s) Max value: 3600000 (1h) | -1 (Do not deduplication) | 2.7.0+ |
Third-party dependencies
Hackle Android SDK has the following third-party dependencies.
- com.squareup.okhttp3:okhttp:3.12.2
- com.google.code.gson:gson:2.8.6
- com.google.android.gms:play-services-base:17.3.0
- androidx.lifecycle:lifecycle-extensions:2.2.0
Find SDK Key
The SDK key can be found in the SDK integration in the dashboard of Hackle. Copy and use the APP
SDK Key.
Step3. A/B test, Feature Flag
A/B test
Before running an A/B test, you must distribute users to the test group and create the logic corresponding to each test group.
User distribution can then be carried out through the hackle SDK.
Test Group
The test group refers to the existing one (control group) and improvement one (treatment group) to be tested, and there may be more than one treatment group. You can configure in the dashboard and for information on how to manage test groups, visit see the document A/B setting.
variation
Input Experiment key and user identifier to the 'variation()' method to distribute users and receive results. You can implement logic by test group afterwards.
The experiment key is a unique number for each A/B test and can be found on the dashboard within the Hackle service.
The example code below inputs the experiment key 42 and there are Group A, Group B as test Group .
// Determine which test group to expose to the user in the A/B test with the test key of 42.
// Returns test group A if the test group can not be decided.
Variation variation = hackleApp.variation(42);
// Logic for Assigned Groups
if (variation == Variation.A) {
// Logic for Group A
} else if (variation == Variation.B) {
// Logic for Group B
}
// Determine which test group to expose to the user in the A/B test with the test key of 42.
// Returns test group A if the test group can not be decided.
val variation = hackleApp.variation(42)
// Logic for Assigned Group
if (variation == Variation.A) {
// Logic for Group A
} else if (variation == Variation.B) {
// Logic for Group B
}
Feature Flag
Feature flag is supported for SDK version 2.0.0+
If you are using the feature flag, please apply SDK version 2.0.0 or higher when adding dependencies.
The feature flags are in the ON state and the OFF state. Different features will be set for each state.
When a user accesses a function with a feature flag applied, the user must be able to receive an on or off state. This status determination can be made via the hackle SDK.
isFeatureOn
Input Feature key to the 'isFeatureOn()' method to receive status results for the user. Implement logic based on subsequent states.
The Feature key is a unique number for each Feature Flag and can be found on the dashboard within the Hackle service.
The example code below input the feature key 42.
// Determine which status to expose to the user in the flag with the flag key of 42.
// Returns off statep if the state can not be decided.
boolean featureOn = hackleApp.isFeatureOn(42);
if (featureOn) {
// Logic for ON
} else {
// Logic for OFF
}
// Determine which status to expose to the user in the flag with the flag key of 42.
// Returns off statep if the state can not be decided.
val featureOn = hackleApp.isFeatureOn(42)
if (featureOn) {
// Logic for ON
} else {
// Logic for OFF
}
Check the exposure results
On the [Dashboard Left Menu Bar] - [A/B Test] or [Feature Flag] page, browse to the detail page for the list of exposed A/B tests or feature flags, and click the Real-Time Exposure tab in the middle of the page to view the distribution results from integrated SDK.
Step 4. Send User Events
The Hackle SDK provides the ability to send user events to the hackle.
At each point where changes in user behavior occur, this feature provides meaningful data about user behavior and allows you to analyze user behavior from those collected data.
track
User events can be sent by passing event keys and user identifiers to the 'track()' method. If necessary, when sending user events, numeric values can be put in 'value' to be sent together.
- You can only put the number type for 'value'
Example
Suppose you have defined an event key called 'purchase' to collect events when the user presses the buy button. At this time, you may want to collect the purchase price together. In this case, you can also receive the purchase amount in 'value'.
/* Example 1: Send event key only */
hackleApp.track("purchase");
/* Example 2: Send event keys and numeric values together */
Event event = Event.builder("purchase")
.value(13200) // Put the numeric value to collect with the event key into the value
.build();
hackleApp.track(event);
/* Example 1: Send event key only */
hackleApp.track("purchase")
/* Example 2: Send event keys and numeric values together */
val event = Hackle.event("purchase") {
value(13200) // Put the numeric value to collect with the event key into the value
}
hackleApp.track(event)
Example 1 only sends event keys; Example 2 shows a case of putting the purchase amount in 'value' to collect the purchase amount together.
Validate the sending of user events
Verify that user events sent by SDK are being collected successfully.
You can check the real-time event collection status by finding events sent to the SDK in the [left menu bar of dashboards] - [Event Management].
Updated 3 months ago