The latest release is available on Bintray.
- Add qonversion to
dependencies
section in your appbuild.gradle
dependencies {
...
implementation "com.qonversion.android.sdk:sdk:1.1.0"
...
}
Qonversion SDK can work in two modes depending on your goals:
-
Without autotracking purchases (manual mode). In this mode your should call SDK methods manualy, when your want to track purchase to Qonversion.
-
With autotracking purchases (auto tracking mode). In this mode, you don’t have to worry about how your purchases tracks to Qonversion, all necessary work will take place inside SDK.
Next, in order will be considered the necessary steps to work in each of the modes
To import the Qonversion SDK, add the following code:
import com.qonversion.android.sdk.Qonversion;
The SDK initialization should be called in your Application
in the onCreate
method.
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
Qonversion.initialize(this, "projectKey", "yourSideUserID");
}
}
public class App : Application {
override fun onCreate() {
super.onCreate();
Qonversion.initialize(this, "projectKey", "yourSideUserID");
}
}
First of all your need setup and initialize Google Play Billing Library, following the documentation
To track purchase data to the SDK you need to call the method purchase
. So this method takes two parameters. All of these parameters is objects from Google Play Billing Library
The best place to call method purchase
it time when method onPurchasesUpdated
of BillingClient
will be called.
For more information please see example app in this repo ManualTrackingActivity and ManualTrackingActivityKt classes.
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
client = BillingClient
.newBuilder(this)
.enablePendingPurchases()
.setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> list) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
if (list != null && !list.isEmpty()) {
trackPurchase(skuDetails.get(SKU_ID), list.get(0));
}
}
}
})
.build();
}
private void trackPurchase(@NonNull SkuDetails details, @NonNull Purchase purchase) {
Qonversion.getInstance().purchase(details, purchase);
}
override fun onCreate(
savedInstanceState: Bundle?,
persistentState: PersistableBundle?
) {
super.onCreate(savedInstanceState, persistentState)
client = BillingClient
.newBuilder(this)
.enablePendingPurchases()
.setListener { billingResult, list ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
if (list != null && list.isNotEmpty()) {
trackPurchase(
skuDetails[SKU_ID]!!,
list[0]
)
}
}
}
.build()
launchBilling()
}
private fun trackPurchase(
details: SkuDetails,
purchase: Purchase
) {
Qonversion.instance!!.purchase(details, purchase)
}
The SDK initialization should be called in your Application
in the onCreate
method following the steps:
To import the Qonversion SDK, add the following code:
import com.qonversion.android.sdk.Qonversion;
Create an instance of QonversionBillingBuilder
. It creation exactly like creation Android BillingClient
private QonversionBillingBuilder buildBilling() {
return new QonversionBillingBuilder()
.enablePendingPurchases()
.setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> purchases) {
// your purchases update logic
}
});
}
private fun buildBilling(): QonversionBillingBuilder {
return QonversionBillingBuilder()
.enablePendingPurchases()
.setListener { billingResult, purchases ->
// your purchases update logic
}
}
To enable auto tracking mode put these parameters to Qonversion initialize
method:
- ApplicationContext
- Your Qonversion API key.
- Your side UserID
- Instance of QonversionBillingBuilder from Step 2.
- Autotracking - Boolean parameter put it to TRUE
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
QonversionBillingBuilder billingBuilder = buildBilling();
Qonversion.initialize(this, "projectKey", "yourSideUserID", billingBuilder, true);
}
class App : Application() {
override fun onCreate() {
super.onCreate()
val billingBuilder = buildBilling()
Qonversion.initialize(this, "projectKey", "yourSideUserID", billingBuilder, true)
}
}
For further work with SDK in auto tracking mode, your should use Qonversion Billing instance.
It has exactly the same interface and methods as Google BillingClient. It’s just enough for you to call Qonversion.instance?.billingClient
And to do what you want in the same way if you used the Google BillingClient. Below are
simplified example of usage.
For more information please see example app in this repo MainActivity
class MainActivity : AppCompatActivity() {
private var billingClient : Billing? = null
private val skuDetailsMap = mutableMapOf<String, SkuDetails>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
billingClient = Qonversion.instance?.billingClient
billingClient?.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
// billing connection failed
}
override fun onBillingSetupFinished(billingResult: BillingResult?) {
if (billingResult?.responseCode == BillingClient.BillingResponseCode.OK) {
launchBilling("your_purchase_id", "sku_type")
}
}
})
}
private fun launchBilling(purchaseId: String, type: String) {
var params = SkuDetailsParams.newBuilder()
.setType(type)
.setSkusList(listOf(purchaseId))
.build()
billingClient?.querySkuDetailsAsync(params, object: SkuDetailsResponseListener {
override fun onSkuDetailsResponse(
billingResult: BillingResult?,
skuDetailsList: MutableList<SkuDetails>?
) {
if (billingResult!!.responseCode == BillingClient.BillingResponseCode.OK) {
for (skuDetails in skuDetailsList!!) {
skuDetailsMap[skuDetails.sku] = skuDetails
}
launchBillingFlow(purchaseId)
}
}
})
}
private fun launchBillingFlow(purchaseId: String) {
val billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsMap[purchaseId])
.build()
billingClient?.launchBillingFlow(this, billingFlowParams)
}
}
You need to have AppsFlyer SDK integrated in your app before starting with this integration.
If you do not have Appsflyer integration yet, please use this docs
When you receive the onConversionDataReceived callback you can use the attribution
method
for passing the attribution data dictionary:
@Override
public void onConversionDataSuccess(final Map<String, Object> conversionData) {
Qonversion.getInstance().attribution(
conversionData,
AttributionSource.APPSFLYER,
AppsFlyerLib.getInstance().getAppsFlyerUID(this)
);
}
override fun onConversionDataSuccess(conversionData: Map<String, Any>) {
Qonversion.instance?.attribution(
conversionData,
AttributionSource.APPSFLYER,
AppsFlyerLib.getInstance().getAppsFlyerUID(applicationContext)
)
}
Developed by Team of Qonversion, and written by Artemy Glukhov
Qonversion SDK is available under the MIT license.