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:
Initialize the YMMMutableAdRevenueInfo instance.
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); }]; }
Copied to clipboard
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)") }
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:
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:@"API_key"]; [YMMYandexMetrica activateWithConfiguration:configuration];
Copied to clipboardlet configuration = YMMYandexMetricaConfiguration.init(apiKey: "API key") YMMYandexMetrica.activate(with: configuration!)
Copied to clipboardAfter debugging, repeat steps 2 and 3 for the main API key.
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); }];
Copied to clipboardYMMYandexMetrica.report(adRevenue: adRevenueInfo) { error in print("AdRevenue error: \(error)") }
Copied to clipboard