Sending information about a purchase on Android

AppMetrica doesn't let you segment Revenue into “test” and “not test”. If you use the main API key for debugging purchases, the test purchases are included in general statistics. Therefore, to debug Revenue sending, use a reporter to send statistics to the additional API key. For more information about reporters, see Usage examples.
  1. Step 1. Create a test app in AppMetrica
  2. Step 2. (Optional) Enable validation
  3. Step 3. Test sending Revenue
  4. Step 4. Make sure that purchases are shown in the reports.
  5. Step 5. Configure sending revenue to the main API key

Step 1. Create a test app in AppMetrica

  1. In the AppMetrica interface, click Add application.

  2. Fill in the fields in the form.
  3. Click Create. By clicking the button, you accept the terms of user agreement.
Note. Different versions of the same app can be grouped in a single folder. To do this, create a folder using the button and move the apps to it.

Step 2. (Optional) Enable validation

Local validation with a public key is used to validate purchases on Android.

To enable validation, create a public key and specify it in the settings.
  1. In the Google interface, get a license key. For more information, see the Google documentation.
  2. In the AppMetrica interface, go to the app settings from the menu on the left.
  3. Go to the Revenue tab.
  4. Under Revenue validation for Google Play, enter the license key.
  5. Click Enable validation.
Attention. If validation is enabled, the Revenue report displays purchases that were validated or were sent without the Revenue.Receipt instance.

Step 3. Test sending Revenue

This section outlines the steps for sending Revenue to the additional API key:

To validate purchases on Android, configure sending the Revenue.Receipt instance along with the Revenue:

  1. Create the Revenue.Receipt instance with information about the purchase and signature. You must use it when creating the Revenue instance in Revenue.Builder.withReceipt (Revenue.Receipt receipt).
  2. Create the Revenue instance using the Revenue.Builder constructor.
  3. Send the Revenue instance to the test API key using IReporter. For more information about reporters, see Usage examples.
void handlePurchase(Purchase purchase) {
    ...
    // Creating the Revenue.Receipt instance.
    // It is used for checking purchases in Google Play.
    Revenue.Receipt revenueReceipt = Revenue.Receipt.newBuilder()
            .withData(purchase.getOriginalJson())
            .withSignature(purchase.getSignature())
            .build();
    // Creating the Revenue instance.
    Revenue revenue = Revenue.newBuilderWithMicros(99000000, Currency.getInstance("RUB"))
            .withProductID("com.yandex.service.299")
            .withQuantity(2)
            .withReceipt(revenueReceipt)
            .withPayload("{\"source\":\"Google Play\"}")
            .build();
    // Sending the Revenue instance using reporter.
    YandexMetrica.getReporter(getApplic