Sending Ad Revenue on Android
Testing and manually sending purchase information
AppMetrica doesn't let you segment Ad Revenue into “test” and “not test”. If you use the main API key for debugging the collection of data on advertising monetization, the test events are included in general statistics. If you need to debug sending Ad Revenue, use a reporter to send statistics to an additional API key.
Step 1. Create a test app in AppMetrica
Specify the app parameters: link in the app store (if the app hasn't been published yet, leave the field empty), name, category, and time zone for generating reports.
To add another app, click Add app in the drop-down list in the AppMetrica interface.
Step 2. Test sending Ad Revenue
This section outlines the steps for sending Ad Revenue to the additional API key:
Create an AdRevenue instance using the AdRevenue.Builder.
Map<String, String> adRevenuePayload = new HashMap<>(); adRevenuePayload.put("payload_key_1", "payload_value_1"); adRevenuePayload.put("payload_key_2", "payload_value_2"); AdRevenue adRevenue = AdRevenue.newBuilder(new BigDecimal("100.100"), Currency.getInstance("USD")) .withAdNetwork("ad_network") .withAdPlacementId("ad_placement_id") .withAdPlacementName("ad_placement_name") .withAdType(AdType.NATIVE) .withAdUnitId("ad_unit_id") .withAdUnitName("ad_unit_name") .withPrecision("some precision") .withPayload(adRevenuePayload) .build();
Copied to clipboardSend the
AdRevenue
instance to the test API key using IReporter. For more information about reporters, see Usage examples.YandexMetrica.getReporter(TEST_API_KEY).reportAdRevenue(adRevenue);
Copied to clipboard
Step 3. Make sure that Ad Revenue info is shown in reports.
View ads in the app.
Make sure that the Revenue report shows the same number of Ad Revenue events as the number of ad views.
Step 4. Set up sending Ad Revenue to the main API key
Make sure that the SDK is activated before sending data to the main API key. Activation example:
YandexMetricaConfig config = YandexMetricaConfig.newConfigBuilder(API_KEY).build(); YandexMetrica.activate(context, config);
Copied to clipboardAfter debugging, repeat steps 2 and 3 for the main API key.
To send the
AdRevenue
instance to the main API key, use the YandexMetrica.reportAdRevenue(AdRevenue adRevenue) method.YandexMetrica.reportAdRevenue(adRevenue);
Copied to clipboard