ממשקי ה-API של תצוגת האינטרנט למודעות מאפשרים לתגים ב-WKWebView
לגשת לאותות מהאפליקציה, וכך לשפר את המונטיזציה של בעלי האפליקציות שסיפקו את התוכן ולהגן על המפרסמים מפני ספאם.
איך זה עובד
התקשורת עם Google Mobile Ads SDK מתבצעת רק בתגובה לאירועי מודעות שמופעלים על ידי אחד מהגורמים הבאים:
ה-SDK מוסיף מטפלים בהודעות ל-WKWebView
הרשום כדי להאזין לאירועי המודעות האלה. כדי להבין טוב יותר איך זה עובד, אפשר לעיין בקוד המקור של דף הבדיקה.
דרישות מוקדמות
- Google Mobile Ads SDK גרסה 9.6.0 ואילך.
מעדכנים את הקובץ
Info.plist
עם המפתח וערך המחרוזת הבאים. הפעולה הזו מדלגת על בדיקה שמתבצעת על ידי Google Mobile Ads SDK לגבי ערךGADApplicationIdentifier
שרלוונטי למפתחים שמטמיעים מודעות מחוץ לתצוגת אינטרנט. אם לא מבצעים את השלב הזה ולא מספקיםGADApplicationIdentifier
, Google Mobile Ads SDK יציגGADInvalidInitializationException
בהפעלת האפליקציה.<!-- Indicate Google Mobile Ads SDK usage is only for web view APIs for ads --> <key>GADIntegrationManager</key> <string>webview</string>
רישום תצוגת האינטרנט
צריך להפעיל את הפונקציה
register(_:)
ב-main thread כדי ליצור קישור ל-JavaScript handlers בקוד AdSense או ב-Google Publisher Tag בכל מופע של WKWebView
. מומלץ לבצע את הפעולה הזו מוקדם ככל האפשר, למשל בשיטה viewDidLoad
של בקר התצוגה.
Swift
import WebKit
class ViewController: UIViewController {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Initialize a WKWebViewConfiguration object.
let webViewConfiguration = WKWebViewConfiguration()
// Let HTML videos with a "playsinline" attribute play inline.
webViewConfiguration.allowsInlineMediaPlayback = true
// Let HTML videos with an "autoplay" attribute play automatically.
webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []
// Initialize the WKWebView with your WKWebViewConfiguration object.
webView = WKWebView(frame: view.frame, configuration: webViewConfiguration)
view.addSubview(webView)
// Register the web view.
MobileAds.shared.register(webView)
}
}
Objective-C
@import WebKit;
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, strong) WKWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize a WKWebViewConfiguration object.
WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init];
// Let HTML videos with a "playsinline" attribute play inline.
webViewConfiguration.allowsInlineMediaPlayback = YES;
// Let HTML videos with an "autoplay" attribute play automatically.
webViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
// Initialize the WKWebView with your WKWebViewConfiguration object.
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];
[self.view addSubview:self.webView];
// Register the web view.
[GADMobileAds.sharedInstance registerWebView:self.webView];
}
בדיקת השילוב
לפני שמשתמשים בכתובת URL משלכם, מומלץ לטעון את כתובת ה-URL הבאה כדי לבדוק את השילוב:
https://google.github.io/webview-ads/test/#api-for-ads-tests
אם מתקיימים התנאים הבאים, כתובת ה-URL של הבדיקה מציגה סרגלי סטטוס ירוקים שמציינים שהשילוב בוצע בהצלחה:
WKWebView
מחובר ל-Google Mobile Ads SDK
השלבים הבאים
- קבלת הסכמה ב-
WKWebView
. ממשקי ה-API של תצוגות האינטרנט לצורך הצגת מודעות לא מעבירים את נתוני ההסכמה שנאספו בהקשר של האפליקציה לנייד באמצעות מסגרות התאימות IAB TCF v2.0 או IAB CCPA לתגים בתצוגות האינטרנט. אם אתם רוצים להטמיע תהליך הסכמה יחיד כבעלים שלWKWebView
ושל תוכן האינטרנט התואם שמניב הכנסות, אתם צריכים לעבוד עם הפלטפורמה לניהול הסכמה כדי לאסוף הסכמה בהקשר שלWKWebView
.