Sending Ad Revenue on iOS

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:

  1. Initialize the YMMMutableAdRevenueInfo instance.

  2. Send the YMMMutableAdRevenueInfo instance to the test API key using the YMMYandexMetricaReporting reporter. For more information on reporters, see Sending statistics to an additional API key.

- (void)reportAdRevenue
{
    NSDecimalNumber *price = [NSDecimalNumber decimalNumberWithString:@"65.5"];
    // Initializing the AdRevenue instance.
    YMMMutableAdRevenueInfo *adRevenueInfo = [[YMMMutableAdRevenueInfo alloc] initWithAdRevenue:price currency:@"USD"];
    adRevenueInfo.adType = YMMAdTypeNative;
    adRevenueInfo.adNetwork = @"Network";
    adRevenueInfo.adUnitID = @"UnitID";
    adRevenueInfo.adUnitName = @"UnitName";
    adRevenueInfo.adPlacementID = @"PlacementID";
    adRevenueInfo.adPlacementName = @"PlacementName";
    adRevenueInfo.adUnitID = @"UnitID";
    adRevenueInfo.precision = @"estimated";
    adRevenueInfo.payload = @{ @"source": @"AppStore" };

    id<YMMYandexMetricaReporting> reporter = [YMMYandexMetrica reporterForApiKey:@"Testing API key"];
    [reporter reportAdRevenue:[adRevenueInfo copy] onFailure:^(NSError *error) {
        NSLog(@"Revenue error: %@", error);
    }];
}
func reportAdRevenue() {
    let price = NSDecimalNumber(string: "65.5")
    // Initializing the AdRevenue instance.
    let adRevenueInfo = YMMMutableAdRevenueInfo.init(adRevenue: price, currency: "USD")
    adRevenueInfo.adType = .native
    adRevenueInfo.adNetwork = "Network"
    adRevenueInfo.adUnitID = "UnitID"
    adRevenueInfo.adUnitName = "UnitName"
    adRevenueInfo.adPlacementID = "PlacementID"
    adRevenueInfo.adPlacementName = "PlacementName"
    adRevenueInfo.adUnitID = "UnitID"
    adRevenueInfo.precision = "estimated"
    adRevenueInfo.payload = ["source": "AppStore"]

    let reporter = YMMYandexMetrica.reporterForApiKey("API_key")
    reporter.report(adRevenue, onFailure: { (error) in
        print("REPORT ERROR: \(error.localizedDescription)")
}

Step 3. Make sure that Ad Revenue info is shown in reports.

  1. View ads in the app.

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

  1. Make sure that the SDK is activated before sending data to the main API key. Activation example:

    YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:@"API_key"];
    [YMMYandexMetrica activateWithConfiguration:configuration];
    
    let configuration = YMMYandexMetricaConfiguration.init(apiKey: "API key")
    YMMYandexMetrica.activate(with: configuration!)
    
  2. After debugging, repeat steps 2 and 3 for the main API key.

  3. To send the YMMMutableAdRevenueInfo instance to the main API key, use the +reportAdRevenue:onFailure: method of the YMMYandexMetrica class.

    [YMMYandexMetrica reportAdRevenue:[adRevenueInfo copy] onFailure:^(NSError *error) {
    NSLog(@"AdRevenue error: %@", error);
    }];
    
    YMMYandexMetrica.report(adRevenue: adRevenueInfo) { error in
    print("AdRevenue error: \(error)")
    }
    

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.

Contact support