通过集成 AdMob 广告收入,您不仅可以收集通过 AdMob 获得的广告收入数据,还可以在 Airbridge 面板按归因和用户进行查看。
AdMob 广告收入的集成是通过 AdMob SDK 获取 AdMob 广告收入数据,然后将此数据传递给 Airbridge SDK 实现的。由于只有在 AdMob 面板中启用 展示机会层级的广告收入 后才能收集 AdMob 广告收入数据,因此为了集成 AdMob 需要安装 AdMob SDK 并启用 AdMob 展示机会层级的广告收入。
提示
此功能处于测试阶段。 如有疑问或功能需求,请联系您的 CSM。
AdMob Android SDK 安装指南(需要 19.0.0 及以上版本)
AdMob iOS SDK 安装指南(需要 7.54.0 及以上版本)
AdMob Unity SDK 安装指南(需要 5.0.0 及以上版本)
请参阅 AdMob 文档。
请使用 AdMob SDK 设置广告收入数据回调,并通过此回调将广告收入数据传递至 Airbridge SDK。
private void RequestRewardedAd()
{
RewardedAd.LoadAd(adUnitId, new AdRequest.Builder().Build(), (rewardedAd, error) => {
if (error != null) { return; }
this.rewardedAd = rewardedAd;
this.rewardedAd.OnPaidEvent += this.HandleAdPaidEvent;
}
}
public void HandleAdPaidEvent(object sender, AdValueEventArgs args)
{
AdValue adValue = args.AdValue;
var adUnitId = this.rewardedAd.adUnitId;
var adNetworkAdapter = this.rewardedAd.MediationAdapterClassName();
AirbridgeEvent @event = new AirbridgeEvent("airbridge.adImpression");
var admob = new Dictionary<string, object>();
admob["value_micros"] = adValue.Value;
admob["currency_code"] = adValue.CurrencyCode;
admob["precision"] = adValue.Precision;
admob["ad_unit_id"] = adUnitId;
admob["ad_network_adapter"] = adNetworkAdapter;
var adPartners = new Dictionary<string, object>();
adPartners["admob"] = admob;
@event.SetAction(adUnitId);
@event.SetLabel(adNetworkAdapter);
@event.SetValue(adValue.Value / 1000000.0);
@event.AddSemanticAttribute("adPartners", adPartners);
@event.AddSemanticAttribute("currency", adValue.CurrencyCode);
AirbridgeUnity.TrackEvent(@event);
}
import GoogleMobileAds
import AirBridge
import UIKit
class ViewController: UIViewController {
var rewardedAd: GADRewardedAd? = nil
func requestRewardedAd() {
let request = GADRequest()
GADRewardedAd.load(
withAdUnitID: "ad unit ID",
request: request
) { ad, error in
if let error {
print("Rewarded ad failed to load with error: \(error.localizedDescription)")
return
}
self.rewardedAd = ad
self.rewardedAd?.paidEventHandler = { value in
let (value, currencyCode, precision) = (
value.value,
value.currencyCode,
value.precision
)
let adUnitID = self.rewardedAd?.adUnitID
let adNetworkAdapter = self.rewardedAd?.responseInfo.adNetworkClassName
let event = ABInAppEvent()
event?.setCategory("airbridge.adImpression")
event?.setAction(adUnitID)
event?.setLabel(adNetworkAdapter)
event?.setValue(value)
event?.setSemantics([
"adPartners": [
"admob": [
"value_micros": value * 1000000.0,
"currency_code": currencyCode,
"precision": precision,
"ad_unit_id": adUnitID ?? NSNull(),
"ad_network_adapter": adNetworkAdapter ?? NSNull(),
]
],
"currency": currencyCode
])
event?.send()
}
}
}
}
@import GoogleMobileAds;
@import AirBridge;
@import UIKit;
@interface ViewController ()
@property(nonatomic, strong) GADRewardedAd *rewardedAd;
@end
@implementation ViewController
- (void)requestRewardedAd {
__weak ViewController* weakSelf = self;
GADRequest* request = [GADRequest request];
[GADRewardedAd loadWithAdUnitID:@"ad unit ID"
request:request
completionHandler:^(GADRewardedAd *ad, NSError *error)
{
if (error) {
NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
return;
}
self.rewardedAd = ad;
self.rewardedAd.paidEventHandler = ^void(GADAdValue *_Nonnull adValue){
ViewController* strongSelf = weakSelf;
// Extract the impression-level ad revenue data.
NSDecimalNumber* value; = adValue.value;
NSString* currencyCode = adValue.currencyCode;
GADAdValuePrecision precision = adValue.precision;
// Get the ad unit ID.
NSString* adUnitId = strongSelf.rewardedAd.adUnitID;
NSString* adNetworkAdapter = strongSelf.rewardedAd.responseInfo.adNetworkClassName;
ABInAppEvent* event = [[ABInAppEvent alloc] init];
[event setCategory:@"airbridge.adImpression"];
[event setAction:adUnitId];
[event setLabel:adNetworkAdapter];
[event setValue:value];
[event setSemantics:@{
@"adPartners": @{
@"admob": @{
@"value_micros": [value decimalNumberByMultiplyingByPowerOf10:6],
@"currency_code": currencyCode,
@"precision": precision,
@"ad_unit_id": adUnitId,
@"ad_network_adapter": adNetworkAdapter
}
},
@"currency": currencyCode
}];
[event send];
};
}];
}
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdValue;
import com.google.android.gms.ads.OnPaidEventListener;
import com.google.android.gms.ads.rewarded.RewardedAd;
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
void requestRewardedAd(Context context) {
AdRequest adRequest = new AdRequest.Builder().build();
RewardedAd.load(context, "ad unit ID", adRequest, new RewardedAdLoadCallback(){
@Override
public void onAdLoaded(@NonNull RewardedAd ad) {
// Set paid event listener
ad.setOnPaidEventListener(new OnPaidEventListener() {
@Override
public void onPaidEvent(AdValue adValue) {
// Extract the impression-level ad revenue data.
long valueMicros = adValue.getValueMicros();
String currencyCode = adValue.getCurrencyCode();
int precision = adValue.getPrecisionType();
// Get the ad unit ID.
String adUnitId = ad.getAdUnitId();
String adNetworkAdapter = ad.getResponseInfo().getMediationAdapterClassName();
Event event = new Event("airbridge.adImpression");
Map<String, Object> admob = new HashMap<>();
admob.put("value_micros", valueMicros);
admob.put("currency_code", currencyCode);
admob.put("precision", precision);
admob.put("ad_unit_id", adUnitId);
admob.put("ad_network_adapter", adNetworkAdapter);
Map<String, Object> adPartners = new HashMap<>();
adPartners.put("admob", admob);
Map<String, Object> semanticAttributes = new HashMap<>();
semanticAttributes.put("adPartners", adPartners);
semanticAttributes.put("currency", currencyCode);
event.setAction(adUnitId);
event.setLabel(adNetworkAdapter);
event.setValue(valueMicros / 1000000.0);
event.setSemanticAttributes(semanticAttributes);
Airbridge.trackEvent(event);
}
});
}
});
}
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.OnPaidEventListener
import com.google.android.gms.ads.rewarded.RewardedAd
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
fun requestRewardedAd(context: Context) {
val adRequest = AdRequest.Builder().build()
RewardedAd.load(context, "ad unit ID", adRequest, object : RewardedAdLoadCallback() {
override fun onAdLoaded(ad: RewardedAd) {
ad.onPaidEventListener = OnPaidEventListener { adValue ->
// Extract the impression-level ad revenue data.
val valueMicros = adValue.valueMicros
val currencyCode = adValue.currencyCode
val precision = adValue.precisionType
// Get the ad unit ID.
val adUnitId = ad.adUnitId
val adNetworkAdapter = ad.responseInfo.mediationAdapterClassName
val event = Event("airbridge.adImpression")
val admob = mutableMapOf<String, Any?>()
admob["value_micros"] = valueMicros
admob["currency_code"] = currencyCode
admob["precision"] = precision
admob["ad_unit_id"] = adUnitId
admob["ad_network_adapter"] = adNetworkAdapter
val adPartners = mapOf("admob" to admob)
event.action = adUnitId
event.label = adNetworkAdapter
event.value = valueMicros / 1000000.0
event.semanticAttributes = mutableMapOf(
"adPartners" to adPartners,
"currency" to currencyCode
)
Airbridge.trackEvent(event)
}
}
})
}
AdMob SDK 传递的收入数据根据平台环境格式不同。例如,收入为 USD 0.005 时,在 Android 和 Unity 环境中返回 5000,而在 iOS 环境中返回 0.005。
上述示例代码指导内容如下:在所有平台上,当 semanticAttributes.adPartners.admob.value_micros
设置为 5000 时,将向 Airbridge SDK 输入 0.005。
Was this page helpful?