کیت توسعه نرمافزاری تبلیغات موبایل گوگل (Google Mobile Ads SDK) از کسب درآمد از برنامهها با استفاده از ویژگی Ad Exchange پشتیبانی میکند. این راهنما به شما نشان میدهد که چگونه برنامههای خود را برای همه قالبهای تبلیغاتی پشتیبانی شده توسط Ad Exchange پیکربندی کنید.
پیشنیازها
برنامه خود را برای دسترسی به Ad Exchange پیکربندی کنید
Add your Ad Manager app ID ( identified in the Ad Manager UI ) to your app's AndroidManifest.xml file through a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID" . For android:value , insert your own Ad Manager app ID, surrounded by quotation marks.
<manifest>
<application>
<!-- Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
همچنین توجه داشته باشید که عدم اضافه کردن تگ <meta-data> همانطور که در بالا نشان داده شده است، منجر به خرابی با پیام زیر میشود:
Missing application ID.
Next, you can initialize the Google Mobile Ads SDK and select an ad format to display. The rest of this guide implements the banner format to illustrate how you can load an ad from Ad Exchange. The same steps can apply to any ad formats supported by the Google Mobile Ads SDK.
بارگذاری تبلیغ از Ad Exchange
شما میتوانید به جای شناسه واحد تبلیغاتی، از کد ویژگی وب Ad Exchange به همراه یک اسلش به جلو استفاده کنید. برای مثال، ca-mb-app-pub-5629679302779023/ .
برای مثال، برای بارگذاری یک بنر تبلیغاتی، یک AdManagerAdView را در طرحبندی Activity به صورت زیر قرار دهید:
# main_activity.xml
...
<com.google.android.gms.ads.admanager.AdManagerAdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adManagerAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-mb-app-pub-5629679302779023/">
</com.google.android.gms.ads.admanager.AdManagerAdView>
به عنوان یک روش جایگزین، میتوانید به صورت برنامهنویسی شده یک سلسله مراتب view ایجاد کنید:
جاوا
AdManagerAdView adView = new AdManagerAdView(this);
adView.setAdSizes(AdSize.BANNER);
adView.setAdUnitId("ca-mb-app-pub-5629679302779023/");
// TODO: Add adView to your view hierarchy.
کاتلین
val adView = AdManagerAdView(this)
adView.adSizes = AdSize.BANNER
adView.adUnitId = "ca-mb-app-pub-5629679302779023/"
// TODO: Add adView to your view hierarchy.
پس از اینکه AdManagerAdView در جای خود قرار گرفت، میتوانید متد loadAd() را در کلاس AdManagerAdView فراخوانی کرده و رفتار تبلیغ خود را با استفاده از رویدادهای تبلیغ سفارشی کنید.
توجه داشته باشید که عدم اضافه کردن یک اسلش به جلو در کد ویژگی وب Ad Exchange منجر به خطای درخواست تبلیغ با پیام زیر میشود:
Invalid Request. Cannot determine request type. Is your ad unit id correct?
You can also convert an Ad Exchange web property code into an ad unit. Afterwards, use the Ad Manager UI to generate an Ad Exchange Tag and copy it into your app. The generated tag should have the Ad Exchange web property code, followed by descendant ad unit IDs without a trailing forward slash, for example: ca-mb-app-pub-5629679302779023/banner .
همین! برنامه شما اکنون آماده بارگیری و نمایش تبلیغات بنری از Ad Exchange است.
علاوه بر این، میتوانید با دنبال کردن راهنماهای مربوطه، از یک ویژگی وب Ad Exchange برای بارگیری و نمایش سایر قالبهای تبلیغاتی از Ad Exchange استفاده کنید:
(فقط ناشران اروپایی مورد تایید) اضافه کردن کف قیمتها
شما میتوانید درخواستی برای ویژگی «کف قیمت» ارسال کنید .
Once approved, you can include a public floor or private floor in the ad request using the pubf and pvtf parameters respectively. In the following code example, replace "123" with the floor prices in micros and your network's default currency . Example of how micros are applied: if your default currency is USD, entering "6000000" is the equivalent of $6.00.
جاوا
Bundle extras = new Bundle();
// Public floor parameter.
extras.putString("pubf", "123");
// Private floor parameter.
extras.putString("pvtf", "123");
AdManagerAdRequest request = new AdManagerAdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
کاتلین
val extras = Bundle();
// Public floor parameter.
extras.putString("pubf", "123");
// Private floor parameter.
extras.putString("pvtf", "123");
val request = AdManagerAdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter::class::java, extras)
.build();