Skip to content

suriksarkisyan/TestRep

Repository files navigation

The latest release is available on Bintray.

Instalation

  1. Add qonversion to dependencies section in your app build.gradle
dependencies {
    ... 
    implementation "com.qonversion.android.sdk:sdk:1.1.0"
    ...
}

Setup

Qonversion SDK can work in two modes depending on your goals:

  1. Without autotracking purchases (manual mode). In this mode your should call SDK methods manualy, when your want to track purchase to Qonversion.

  2. 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

1. Manual mode

1.1 Initializing Qonversion SDK

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.

Java

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Qonversion.initialize(this, "projectKey", "yourSideUserID");
    }
}

Kotlin

public class App : Application {
    override fun onCreate() {
        super.onCreate();
        Qonversion.initialize(this, "projectKey", "yourSideUserID");
    }
}

1.2 Usage Qonversion SDK in manual mode

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

  • details with type SkuDetails docs.
  • purchase with type Purchase docs.

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.

Java

@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);
}

Kotlin

    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)
    }

2. Auto Tracking mode

2.1 Initializing Qonversion SDK

The SDK initialization should be called in your Application in the onCreate method following the steps:

Step 1. Add Qonversion SDK import

To import the Qonversion SDK, add the following code:

import com.qonversion.android.sdk.Qonversion;

Step 2. Initialize QonversionBillingBuilder

Create an instance of QonversionBillingBuilder. It creation exactly like creation Android BillingClient

Java

    private QonversionBillingBuilder buildBilling() {
        return new QonversionBillingBuilder()
                .enablePendingPurchases()
                .setListener(new PurchasesUpdatedListener() {
                    @Override
                    public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> purchases) {
                        // your purchases update logic
                    }
                });
    }

Kotlin

    private fun buildBilling(): QonversionBillingBuilder {
        return QonversionBillingBuilder()
            .enablePendingPurchases()
            .setListener { billingResult, purchases ->
                // your purchases update logic
            }
    }

Step 3. Initializing Qonversion SDK.

To enable auto tracking mode put these parameters to Qonversion initialize method:

  1. ApplicationContext
  2. Your Qonversion API key.
  3. Your side UserID
  4. Instance of QonversionBillingBuilder from Step 2.
  5. Autotracking - Boolean parameter put it to TRUE

Java

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        QonversionBillingBuilder billingBuilder = buildBilling();
        Qonversion.initialize(this, "projectKey", "yourSideUserID", billingBuilder, true);
    }

Kotlin

class App : Application() {

    override fun onCreate() {
        super.onCreate()
        val billingBuilder = buildBilling()
        Qonversion.initialize(this, "projectKey", "yourSideUserID", billingBuilder, true)
    }
}

2.2. Use Qonversion Billing instead Google BillingClient

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)
    }
}

3. Attribution

3.1 AppsFlyer

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:

Java

    @Override
    public void onConversionDataSuccess(final Map<String, Object> conversionData) {
          Qonversion.getInstance().attribution(
                  conversionData, 
                  AttributionSource.APPSFLYER, 
                  AppsFlyerLib.getInstance().getAppsFlyerUID(this)
                  );
    }

Kotlin

    override fun onConversionDataSuccess(conversionData: Map<String, Any>) {
        Qonversion.instance?.attribution(
            conversionData,
            AttributionSource.APPSFLYER,
            AppsFlyerLib.getInstance().getAppsFlyerUID(applicationContext)
        )
    }

Authors

Developed by Team of Qonversion, and written by Artemy Glukhov

License

Qonversion SDK is available under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •