该 API 采用 publisher-subscriber (发布-订阅) 架构。
MAX SDK 会广播 MAX 广告收入事件,MMP 订阅 max_revenue_events 主题。
AppLovin 建议您在应用启动后立即订阅该主题,
避免错过任何事件。
每个广播事件都包含以下参数:
| 名称 | 描述 | 示例 |
|---|---|---|
ad_format | 广告格式。 | BANNER, MREC, INTER, REWARDED |
country_code | 收入国家代码。 | US (针对美国) |
id | 广告的唯一内部 ID。 | 19017d954ffcded6c42772b09ec36699efe0bfc2 |
max_ad_unit_id | MAX Ad Unit ID。 | 65d8d0195e50bda6 |
network_name | 显示广告展示所在平台的名称。 | AppLovin |
revenue | 代表收入额的双精度值。 | 0.002067201 |
third_party_ad_placement_id | 广告的 placement ID(如有。竞价可能没有 placement ID)。 | inter_regular |
user_segment | 接受广告展示的用户所处的用户分群。 | experiment5 |
MMP 负责设置这些广播事件中的参数值。 如果您未能收到广播事件中 1 个或多个参数,或收到了不可靠的数据,请联系您的 MMP,确保 MMP 支持所有相关参数。
请参考下方示例,了解如何订阅和处理 SDK 广播的事件。
#import "ExampleViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>
@interface ExampleViewController()<ALCSubscriber>
@end
@implementation ExampleViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[ALCCommunicator defaultCommunicator] subscribe: self forTopic: @"max_revenue_events"];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear: animated];
// Unsubscribe when subscription is no longer needed
[[ALCCommunicator defaultCommunicator] unsubscribe: self forTopic: @"max_revenue_events"];
}
#pragma mark - AppLovin Communicator Subscriber Protocol
- (void)didReceiveMessage:(ALCMessage *)message
{
// If you are subscribed to multiple topics, check for the desired one
if ( [@"max_revenue_events" isEqualToString: message.topic] )
{
double revenue = [message.data[@"revenue"] doubleValue];
// MAX revenue event messages will also contain the same info as MAX ad event messages, but without the "type"
NSString *countryCode = message.data[@"country_code"]; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
NSString *networkName = message.data[@"network_name"]; // Display name of the network which showed the ad
NSString *adUnitIdentifier = message.data[@"max_ad_unit_id"]; // The MAX Ad Unit ID
NSString *thirdPartyAdPlacementIdentifier = message.data[@"third_party_ad_placement_id"]; // The ad's placement id, if any (bidding may not have one)
NSString *adFormat = message.data[@"ad_format"]; // The ad format of the ad (e.g. "BANNER", "MREC", "INTER", "REWARDED")
}
}
- (NSString *)communicatorIdentifier;
{
return @"«your_company_name_in_snake_case»";
}
@end
import UIKit
import AppLovinSDK
class ExampleViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
ALCCommunicator.default.subscribe(self, forTopic: "max_revenue_events")
}
override func viewWillDisappear(_ animated: Bool)
{
super.viewWillDisappear(animated)
// Unsubscribe when subscription is no longer needed
ALCCommunicator.default.unsubscribe(self, forTopic: "max_revenue_events")
}
}
// MARK: - AppLovin Communicator Subscriber Protocol
extension ALInterstitialAdTestViewController : ALCSubscriber
{
func didReceive(_ message: ALCMessage)
{
// In the case that you are subscribed to multiple topics, check for the desired one
if "max_revenue_events" == message.topic
{
let revenue = message.data["revenue"] as! Double
// MAX revenue event messages will also contain the same info as MAX ad event messages, but without the "type"
let countryCode = message.data["country_code"] as! String // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
let networkName = message.data["network_name"] as! String // Display name of the network which showed the ad
let adUnitId = message.data["max_ad_unit_id"] as! String // The MAX Ad Unit ID
let thirdPartyAdPlacementId = message.data["third_party_ad_placement_id"] as! String // The ad's placement id, if any (bidding may not have one)
let adFormat = message.data["ad_format"] as! String // The ad format of the ad (e.g. "BANNER", "MREC", "INTER", "REWARDED")
}
}
func communicatorIdentifier() -> String
{
return "«your_company_name_in_snake_case»"
}
}
出现错误时,"revenue" 的值可能为 -1。