ממשקי ה-API של תצוגת האינטרנט למודעות מאפשרים לתגים ב-WebView לגשת לאותות מהאפליקציה, וכך לשפר את המונטיזציה של בעלי התוכן הדיגיטלי שסיפקו את התוכן ולהגן על המפרסמים מפני ספאם.
איך זה עובד
התקשורת עם GMA Next Gen SDK מתבצעת רק בתגובה לאירועים שקשורים למודעות, שמופעלים על ידי כל אחד מהגורמים הבאים:
ה-SDK מוסיף מטפלים בהודעות ל-WebView הרשום כדי להאזין לאירועי המודעות האלה. כדי להבין טוב יותר איך זה עובד, אפשר לעיין בקוד המקור של דף הבדיקה.
דרישות מוקדמות
- GMA Next Gen SDK גרסה 0.6.0-alpha01 ואילך.
העברת מזהה האפליקציה אל ה-SDK
אם כבר יש לכם מזהה אפליקציה ב-AdMob, צריך להפעיל את GMA SDK מהדור הבא באמצעות מזהה האפליקציה הקיים.
אם אין לכם מזהה אפליקציה ב-AdMob, צריך להעביר את הערך InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID כמזהה האפליקציה כשמפעילים את GMA Next Gen SDK.
Kotlin
MobileAds.initialize(
this@MainActivity,
// Use this application ID to initialize the GMA Next Gen SDK if
// you don't have an AdMob application ID.
InitializationConfig.Builder(InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID)
.build(),
) {
// Adapter initialization complete.
}
Java
MobileAds.initialize(
this,
// Use this application ID to initialize the GMA Next Gen SDK if
// you don't have an AdMob application ID.
new InitializationConfig.Builder(InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID)
.build(),
initializationStatus -> {
// Adapter initialization is complete.
});
רישום תצוגת האינטרנט
צריך להפעיל את הפונקציה
registerWebView()
ב-main thread כדי ליצור קישור ל-JavaScript handlers בקוד AdSense או ב-Google Publisher Tag בכל מופע של WebView. מומלץ לעשות את זה מוקדם ככל האפשר, למשל בשיטה onCreate() של MainActivity.
Kotlin
import android.webkit.CookieManager
import android.webkit.WebView
import com.google.android.libraries.ads.mobile.sdk.MobileAds
class MainActivity : AppCompatActivity() {
lateinit var webView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
webView = findViewById(R.id.webview)
// Let the web view accept third-party cookies.
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
// Let the web view use JavaScript.
webView.settings.javaScriptEnabled = true
// Let the web view access local storage.
webView.settings.domStorageEnabled = true
// Let HTML videos play automatically.
webView.settings.mediaPlaybackRequiresUserGesture = false
// Register the web view.
MobileAds.registerWebView(webView)
}
}
Java
import android.webkit.CookieManager;
import android.webkit.WebView;
import com.google.android.libraries.ads.mobile.sdk.MobileAds;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webview);
// Let the web view accept third-party cookies.
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
// Let the web view use JavaScript.
webView.getSettings().setJavaScriptEnabled(true);
// Let the web view access local storage.
webView.getSettings().setDomStorageEnabled(true);
// Let HTML videos play automatically.
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
// Register the web view.
MobileAds.registerWebView(webView);
}
}
בדיקת השילוב
לפני שמשתמשים בכתובת URL משלכם, מומלץ לטעון את כתובת ה-URL הבאה כדי לבדוק את השילוב:
https://google.github.io/webview-ads/test/#api-for-ads-tests
אם מתקיימים התנאים הבאים, כתובת ה-URL של הבדיקה מציגה סרגלי סטטוס ירוקים שמציינים שהשילוב בוצע בהצלחה:
WebViewמחובר ל-GMA Next Gen SDK
השלבים הבאים
- קבלת הסכמה ב-
WebView. ממשקי ה-API של תצוגות אינטרנט למודעות לא מעבירים את ההסכמה שנאספה בהקשר של האפליקציה לנייד באמצעות IAB TCF גרסה 2.0 או IAB CCPA, אל התגים בתצוגות האינטרנט. אם אתם רוצים להטמיע תהליך הסכמה יחיד כבעלים שלWebViewושל תוכן האינטרנט התואם שמניב הכנסות, אתם צריכים לעבוד עם הפלטפורמה לניהול הסכמה כדי לקבל הסכמה בהקשר שלWebView.