高级设置
广告位
您可以为每个广告单元设置广告位名称 (例如 “Rewarded VideoLevels”、“INTER_levelEnd” 或 “RewardedVideoCoinStore”)。 这可以帮助您汇总不同广告位类别的统计数据。 下面的片段展示了如何为不同的广告格式设置广告位名称。
横幅 / MREC
adView.placement = @"«placement»";[adView loadAd];adView.placement = "«placement»"adView.loadAd()插屏
[interstitialAd showAdForPlacement: @"«placement»"];interstitial.show(forPlacement: "«placement»")激励广告
[rewardedAd showAdForPlacement: @"«placement»"];rewardedAd.show(forPlacement: "«placement»")原生广告
nativeAdLoader.placement = @"«placement»";nativeAdLoader.placement = "«placement»"原生广告 (Ad Placer)
MAAdPlacerSettings *settings = [MAAdPlacerSettings settingsWithAdUnitIdentifier: @"«ad-unit-ID»"];settings.placement = @"«placement»";let settings = MAAdPlacerSettings(adUnitIdentifier: "«ad-unit-ID»")settings.placement = "«placement»"静音
您可以在启动应用时将某些聚合 SDK 平台的音频设为静音。 通过 AppLovin SDK 支持此功能的平台如下:
- AppLovin
- Bigo (仅限原生广告)
- DT Exchange
- Google Ad Manager
- Google 竞价 and Google AdMob.
- LINE
- Mintegral
对于其他平台,请咨询平台客户团队,了解此功能是否可用以及如何访问。
下面的代码片段展示了如何在支持静音的平台中设置静音:
ALSdk *sdk = [ALSdk shared];sdk.settings.muted = YES; // to mutesdk.settings.muted = NO; // to unmutelet sdk = ALSdk.shared()sdk.settings.isMuted = true /// to mutesdk.settings.isMuted = false /// to unmute启用详细日志
启用详细日志的方法有两种:
编程方式
您可以在 SDK 设置对象中,将标记 isVerboseLoggingEnabled 设置为 YES,以启用详细日志。
[ALSdk shared].settings.verboseLoggingEnabled = YES;ALSdk.shared().settings.isVerboseLoggingEnabled = trueInfo.plist
您还可以在应用的 Info.plist 中,将 AppLovinVerboseLoggingOn 设置为 YES,以启用详细日志。

验证
要验证是否已成功启用详细日志,请查看 AppLovin SDK 日志初始化部分中是否有 Verbose Logging On: true行。
AppLovin SDKVersion: 11.4.2⋮Verbose Logging On: true⋮AppLovin SDK 的日志标签为 “/AppLovinSdk: [AppLovinSdk]”。
Creative ID 和平台名称
您可以调取各个聚合平台已展示广告的 Creative ID 和平台名称。 请参阅 the Creative Debugger documentation 了解更多信息。
DSP 名称
您可以使用如下代码,调取 AppLovin Exchange 投放的 MAX 广告的 DSP 名称:
- (void)didLoadAd:(MAAd *)ad{ NSLog(@"AppLovin Exchange DSP name: %@", ad.DSPName);}func didLoad(_ ad: MAAd){ print("AppLovin Exchange DSP name: (ad.dspName?)")}展示层级 User Revenue API
You can access impression-level user revenue data on the client side. You can use this data to compare different sources and campaigns. You can also access this data by using the MAX User Revenue API. MMPs who want to access this data should refer to the Impression-Level User Revenue API for MMPs page.
您可以针对所有受支持的平台与 Adjust 等移动监测合作伙伴分享展示层级广告收入数据。
You can retrieve the revenue amount in all ad lifecycle callbacks. The following example shows how to do this in the “ad revenue paid” callback:
- (void)didPayRevenueForAd:(MAAd *)ad{ double revenue = ad.revenue; // In USD
// Miscellaneous data NSString *countryCode = [ALSdk shared].configuration.countryCode; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD" NSString *networkName = ad.networkName; // Display name of the network that showed the ad NSString *adUnitId = ad.adUnitIdentifier; // The MAX Ad Unit ID MAAdFormat *adFormat = ad.format; // The ad format of the ad (e.g. BANNER, MREC, INTERSTITIAL, REWARDED) NSString *placement = ad.placement; // The placement this ad's postbacks are tied to NSString *networkPlacement = ad.networkPlacement; // The placement ID from the network that showed the ad}func didPayRevenue(_ ad: MAAd){ let revenue = ad.revenue // In USD
// Miscellaneous data let countryCode = ALSdk.shared().configuration.countryCode // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD" let networkName = ad.networkName // Display name of the network that showed the ad let adUnitId = ad.adUnitIdentifier // The MAX Ad Unit ID let adFormat = ad.format // The ad format of the ad (e.g. BANNER, MREC, INTERSTITIAL, REWARDED) let placement = ad.placement // The placement this ad's postbacks are tied to let networkPlacement = ad.networkPlacement // The placement ID from the network that showed the ad}您还可以获取收入值的精确度评估,如下所示:
NSString *revenuePrecision = ad.revenuePrecision;let revenuePrecision = ad.revenuePrecision该精确度采用下列值之一:
"publisher_defined"- 收入金额为开发者指定的价格
"exact"- 收入金额为实时竞价的结果
"estimated"- 收入金额基于 Auto-CPM 或 FB 竞价估算
"undefined"- 未定义收入金额,也没有足够的数据来估算
""- 收入和精确度无效(例如在测试模式下)
建立广告请求回传
要监听广告请求的发出,请设置一个 MAAdRequestDelegate,实现它的 [didStartAdRequestForAdUnitIdentifier:] 方法,然后将委托设置为 requestDelegate。
以下示例展示了如何在 “ad request started” 回传中执行此操作:
- (void)didStartAdRequestForAdUnitIdentifier:(NSString *)adUnitIdentifier{ // Ad request started here}func didStartAdRequest(forAdUnitIdentifier adUnitIdentifier: String){ // Ad request started here}选择性初始化
You can initialize the SDK with specific ad units by specifying those ad units in the ALSdkInitializationConfiguration.
If you do so, the SDK initializes only those networks that you configured for the ad units you specify.
(If you do not specify any ad units, the SDK assumes the current session needs all your ad units.
If so, it initializes all networks that you configured for them.)
The following example shows how you implement this feature:
ALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey:«your-SDK-key» builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) { builder.mediationProvider = ALMediationProviderMAX; builder.adUnitIdentifiers = @[@"«ad-unit-ID-1»", @"«ad-unit-ID-2»"]; }];
[[ALSdk shared] initializeWithConfiguration: initConfig completionHandler:^(ALSdkConfiguration *sdkConfig) { ⋮}];let initConfig = ALSdkInitializationConfiguration.configuration( withSdkKey: "«your-SDK-key»") { builder in builder.mediationProvider = ALMediationProviderMAX builder.adUnitIdentifiers = ["«ad-unit-ID-1»", "«ad-unit-ID-2»"]}
ALSdk.shared().initialize(with: initConfig) { sdkConfig in ⋮}您可以在 AppLovin 控制面板的 Account > General > Keys 部分找到 SDK Key。
Waterfall Information API
Waterfall Information API 可向您展示广告的当前瀑布流 (已加载或加载失败的广告)。 API 会返回瀑布流中每则广告的广告加载状态、延迟、配置信息和聚合平台信息。 如果瀑布流中的广告加载失败,API 会提供错误信息。
AdLoadState 值
| 值 | 解释 |
|---|---|
| 0 | 未尝试加载广告 |
| 1 | 广告已加载 |
| 2 | 广告加载失败 |
示例
- (void)didLoadAd:(MAAd *)ad{ NSLog(@"Waterfall Name: %@ and Test Name: %@", ad.waterfall.name, ad.waterfall.testName); NSLog(@"Waterfall latency was: %f seconds", ad.waterfall.latency);
for (MANetworkResponseInfo *networkResponse in ad.waterfall.networkResponses) { NSLog(@"Network -> %@", networkResponse.mediatedNetwork); NSLog(@"...adLoadState: %ld", (long) networkResponse.adLoadState); NSLog(@"...latency: %f seconds", networkResponse.latency); NSLog(@"...credentials: %@", networkResponse.credentials); if (networkResponse.error) { NSLog(@"...error: %@", networkResponse.error); } }}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error{ if (!error.waterfall) { return; }
MAAdWaterfallInfo *waterfall = error.waterfall; NSLog(@"Waterfall Name: %@ and Test Name: %@", waterfall.name, waterfall.testName); NSLog(@"Waterfall latency was: %f seconds", waterfall.latency);
for (MANetworkResponseInfo *networkResponse in waterfall.networkResponses) { NSLog(@"Network -> %@", networkResponse.mediatedNetwork); NSLog(@"...latency: %f seconds", networkResponse.latency); NSLog(@"...credentials: %@", networkResponse.credentials); if (networkResponse.error) { NSLog(@"...error: %@", networkResponse.error); } }}func didLoad(_ ad: MAAd){ print("Waterfall Name: (ad.waterfall.name) and Test Name: (ad.waterfall.testName)") print("Waterfall latency was: (ad.waterfall.latency) seconds")
for networkResponse in ad.waterfall.networkResponses { print("Network -> (networkResponse.mediatedNetwork)") print("...adLoadState: (networkResponse.adLoadState.rawValue)") print("...latency: (networkResponse.latency) seconds") print("...credentials: (networkResponse.credentials)") if let networkError = networkResponse.error { print("...error: (networkError)") } }}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError){ guard let waterfall = error.waterfall else { return } print("Waterfall Name: (waterfall.name) and Test Name: (waterfall.testName)") print("Waterfall latency was: (waterfall.latency) seconds")
for networkResponse in waterfall.networkResponses { print("Network -> (networkResponse.mediatedNetwork)") print("...latency: (networkResponse.latency) seconds") print("...credentials: (networkResponse.credentials)") if let networkError = networkResponse.error { print("...error: (networkError)") } }}Waterfall Name: Default Waterfall and Test Name: ControlWaterfall latency was: 4.1710309982299805 secondsNetwork -> [MAMediatedNetworkInfo: name=Fyber, adapterClassName=ALInneractiveMediationAdapter, adapterVersion=8.1.1.0, sdkVersion=8.1.1]...adLoadState: 2...latency: 0.0057220458984375 seconds...credentials: ["placement_id": 235786, "app_id": 106516]...error: [MAAdapterError: errorCode=-5202, errorMessage="Invalid Configuration", thirdPartySdkErrorCode=495, thirdPartySdkErrorMessage="The operation couldn’t be completed. (There is no 235786 spot ID in current app config error 495.)"]
Network -> [MAMediatedNetworkInfo: name=AdMob, adapterClassName=ALGoogleMediationAdapter, adapterVersion=8.13.0.2, sdkVersion=afma-sdk-i-v8.13.0]...adLoadState: 1...latency: 3.0903170108795166 seconds...credentials: ["app_id": ca-app-pub-3555987499620362~1761536714, "event_id": 7f40fb8a9d64cbf1156909a514e53d8181fcf7a3, "placement_id": ca-app-pub-3555987499620362/1638443478]
Network -> [MAMediatedNetworkInfo: name=ironSource, adapterClassName=ALIronSourceMediationAdapter, adapterVersion=7.1.12.0.0, sdkVersion=7.1.12]...adLoadState: 0...latency: -1.0 seconds...credentials: ["placement_id": 1082713, "app_key": 882393cd]Note that if the waterfall is empty, MAError.waterfall returns nil and so you cannot interrogate the waterfall properties.
However you can retrieve the ad load latency for an empty waterfall via requestLatency:
- (void)didLoadAd:(MAAd *)ad{ NSLog(@"Succesful ad load latency: %f seconds", ad.requestLatency);}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error{ NSLog("Failed ad load latency: %f seconds", error.requestLatency);}func didLoad(_ ad: MAAd){ print("Successful ad load latency: (ad.requestLatency) seconds")}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError){ print("Failed ad load latency: (error.requestLatency) seconds")}自定义横幅 / MREC 广告刷新
You can customize banner and MREC ad refresh intervals directly in your integration, just as you can configure them in the Ad Unit UI. The minimum refresh interval is 10 seconds. The maximum refresh interval is 120 seconds. MAX ignores values outside these limits. The following code samples show you how to customize these refresh intervals:
// Where adView is an instance of MAAdView[adView setExtraParameterForKey: @"ad_refresh_seconds" value: «ad-refresh-rate»];// Where adView is an instance of MAAdViewadView.setExtraParameter("ad_refresh_seconds", «ad-refresh-rate»)音频设置
为避免插屏广告和激励广告音频干扰应用的背景音频,AppLovin 建议您在显示广告前暂停应用的背景音频,并在隐藏广告后再恢复应用的背景音频。
- (void)didDisplayAd:(MAAd *)ad{ // Pause your app's background audio}
- (void)didHideAd:(MAAd *)ad{ // Resume your app's background audio}func didDisplay(_ ad: MAAd){ // Pause your app's background audio}
func didHide(_ ad: MAAd){ // Resume your app's background audio}