跳转到内容

针对 MMP 的展示层级用户收入 API

该 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_idMAX Ad Unit ID。65d8d0195e50bda6
network_name广告展示所在平台的显示名称。AppLovin
revenue代表收入金额的双精度值。0.002067201
third_party_ad_placement_id广告的 placement ID(如有。竞价可能没有 placement ID)。inter_regular
user_segment接受广告展示的用户所处的用户分群。experiment5

请参考下方示例,了解如何订阅和处理 SDK 广播的事件。

package «your.package.name»;
import android.app.Activity;
import android.os.Bundle;
import com.applovin.communicator.AppLovinCommunicator;
import com.applovin.communicator.AppLovinCommunicatorMessage;
import com.applovin.communicator.AppLovinCommunicatorSubscriber;
import androidx.annotation.Nullable;
public class ExampleActivity
extends Activity
implements AppLovinCommunicatorSubscriber
{
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
{
super.onCreate( savedInstanceState );
AppLovinCommunicator.getInstance( getApplicationContext() ).subscribe( this, "max_revenue_events" );
}
@Override
protected void onDestroy()
{
// Unsubscribe when subscription is no longer needed
AppLovinCommunicator.getInstance( getApplicationContext() ).unsubscribe( this, "max_revenue_events" );
super.onDestroy();
}
@Override
public void onMessageReceived(final AppLovinCommunicatorMessage message)
{
// If you are subscribed to multiple topics, check for the desired one
if ( "max_revenue_events".equals( message.getTopic() ) )
{
Bundle data = message.getMessageData();
double revenue = data.getDouble( "revenue" );
// Miscellaneous data
String countryCode = data.getString( "country_code" ); // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
String networkName = data.getString( "network_name" ); // Display name of the network which showed the ad
String adUnitId = data.getString( "max_ad_unit_id" ); // The MAX Ad Unit ID
String thirdPartyAdPlacementId = data.getString( "third_party_ad_placement_id" ); // The ad's placement id, if any (bidding may not have one)
String adFormat = data.getString( "ad_format" ); // The ad format of the ad (e.g. "BANNER", "MREC", "INTER", "REWARDED", "REWARDED_INTER")
}
}
@Override
public String getCommunicatorId()
{
return "«your_company_name_in_snake_case»";
}
}