In-App purchase tracking will work only in connection with Adjust/Appsflyer. To connect them, follow this guide for Adjust and this guide for Appsflyer.

It's possible to track in-app purchase information and send info to Appodeal servers for analytics. It allows to group users by the fact of purchasing in-apps. This will help you to adjust the ads for such users or simply turn it off, if needed. To make this setting work correctly, please submit the purchase info via the Appodeal SDK.

Step 1. Validate in-app purchases

To track in-app purchase, Appodeal SDK will need info about purchase provided by the Google Play Billing Library.

Add the following dependency into your module-level build.gradle:

dependencies {
    // ... other project dependencies
    implementation "com.android.billingclient:billing:5.0.0"
}

Get your Purchase and SkuDetails objects from the Google Play Billing Library using the guide. Get a price and currency from SkuDetails.

Create and validate in-app purchase using the method below:

// Purchase object is returned by Google API in onPurchasesUpdated() callback
public void validatePurchase(Purchase purchase) {
    
   // Create new InAppPurchase
   InAppPurchase inAppPurchase = InAppPurchase.newBuilder("PURCHASE_TYPE")
        .withPublicKey("YOUR_PUBLIC_KEY")
        .withSignature(purchase.getSignature())
        .withPurchaseData(purchase.getOriginalJson())
        .withPurchaseToken(purchase.getPurchaseToken())
        .withPurchaseTimestamp(purchase.getPurchaseTime())
        .withDeveloperPayload(purchase.getDeveloperPayload())
        .withOrderId(purchase.getOrderId())          
        //Stock keeping unit id from Google API  
        .withSku(...)
        //Price from Stock keeping unit         
        .withPrice(...)
        //Currency from Stock keeping unit 
        .withCurrency(...)
        //Appodeal In-app event if needed 
        .withAdditionalParams(...)
        .build();	 

   // Validate InApp purchase
   Appodeal.validateInAppPurchase(this, inAppPurchase, new  InAppPurchaseValidateCallback () {
        @Override
        public void onInAppPurchaseValidateSuccess(@NonNull InAppPurchase purchase,
                                                   @Nullable List<ServiceError> errors) {
            // In-App purchase validation was validated successfully by at least one
            // connected service
        }

        @Override
        public void onInAppPurchaseValidateFail(@NonNull List<ServiceError> errors) {
            // In-App purchase validation was failed by all connected service
        }
    });
}

Please make sure if you have created in-app product in Google Play Console → Monetize section to use:

  • InAppPurchase.Type.InApp for purchase type,
  • InAppPurchase.Type.Subs for subscription.
ParameterDescriptionUsage
purchaseTypePurchase type. Must be InAppPurchase.Type.InApp or InAppPurchase.Type.SubsAdjust/AppsFlyer
publicKeyPublic key from Google Developer Console.AppsFlyer
signatureTransaction signature (returned from Google API when the purchase is completed).Adjust/AppsFlyer
purchaseDataProduct purchased in JSON format (returned from Google API when the purchase is completed).AppsFlyer
purchaseTokenProduct purchased token (returned from Google API when the purchase is completed).Adjust
purchaseTimestampProduct purchased timestamp (returned from Google API when the purchase is completed).Adjust
developerPayloadProduct purchased developer payload (returned from Google API when the purchase is completed).Adjust
orderIdProduct purchased unique order id for the transaction (returned from Google API when the purchase is completed).Adjust
skuStock keeping unit id.Adjust
priceIn-app event revenue.Adjust/AppsFlyer/Appodeal
currencyIn-app event currency.Adjust/AppsFlyer/Appodeal
additionalParametersAdditional parameters of the in-app event.

Required parameters:

  • purchaseType
  • purchaseToken
  • developerPayload
  • sku
  • price
  • currency
  • additionalParameters

In-App purchase validation runs by FIFO queue in a single thread. 

Step 2. Generate json file in Google Cloud

  1. Login to Google Cloud with your credentials.
  2. Select Google Play Console Developer project on the top left corner as shown below.

    Please make sure to select Google Play Console Developer project at this step instead of your exact app project. Google Play Console only allows to link Google Play Console Developer cloud projects (later in step 3).

  3. Select Credentials →  Create Credentials →  select Service Account.


  4. Select Viewer as a role for Service Account and press Done.


  5. Go to your service account and press keys →  Add key →  choose JSON → and send us the JSON file via email support@appodeal.com or a live chat.

Step 3. Add required permissions in Google Play Console

  1. Go to the Google Play Console and log in.
  2. Go to Google Play Console->Manage developer accounts->Choose developer account-> Setup->API Access and choose your Google Play Console Developer project from step 2 where you have created your Service Account. 

    If you are not able to see Google Play Console Developer project in the list then please update the webpage.

    If the issue persists, make sure that your Google Play developer account(email) is the owner of the Google Cloud project. You can read more here.

  3. At the bottom there will be a list of service accounts that are available in this Google Cloud project. Select the one from which the JSON was sent. 

    Press Refresh if you are not able to see your Service Account.



  4. Press View Play Console permissions. In the App Permissions section select the necessary applications where in-app events will be used.


  5. Go to Account Permissions section and select all Financial Data permissions:
    • View financial data
    • Manage Orders, subscriptions

Step 4. Contact us

After all completed steps contact our support team via email support@appodeal.com or a live chat with the following information :

  1. Service account JSON file.
  2. Purchases implementation logic in your app (when and where you call validate method and validate purchases).
  3. Send us the purchase testing access through Google Developer console to email support@appodeal.com.
  4. Your apk in zip for testing.