-
Notifications
You must be signed in to change notification settings - Fork 319
[Feature Request] WebView API for Ads #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @yo1106, thanks for filing the issue. Labeling this issue as a feature request. |
It's highly desired feature in my project to register flutter webview to allow AdSense ads. Thanks. |
Feature support for the WebView API is currently planned and will leverage webview_flutter. The tentative timeline for implementing this feature is Q4 2022. |
Will Google accept if I run my ads on the flutter framework's webview widget? Because my account kept getting policy violations that said invalid traffic. Not sure if google labels traffic from webviews as invalid traffic. Is there a temporary workaround to this? |
Google mobile ads rendered in WebViews must meet the technical requirements for web content viewing frames. If they do not, this violates policy. I'll defer to @bparrishMines on whether there is a workaround to share. |
Is there no workaround for this? I am losing revenue and my wordpress website is being suspended for invalid traffic. |
This isn't directly supported by the You'll need to:
Android import android.webkit.WebView;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView;
import io.flutter.plugins.webviewflutter.WebViewFlutterPlugin;
import io.flutter.plugins.webviewflutter.WebViewHostApiImpl;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
final WebViewFlutterPlugin webViewPlugin =
(WebViewFlutterPlugin) flutterEngine.getPlugins().get(WebViewFlutterPlugin.class);
final WebViewHostApiImpl apiImpl =
new WebViewHostApiImpl(
webViewPlugin.getInstanceManager(), new WebViewHostApiImpl.WebViewProxy(), this, null) {
@Override
public void create(Long instanceId, Boolean useHybridComposition) {
super.create(instanceId, useHybridComposition);
final WebView webView = getInstanceManager().getInstance(instanceId);
// MobileAds.registerWebView(webView);
}
};
GeneratedAndroidWebView.WebViewHostApi.setup(flutterEngine.getDartExecutor(), apiImpl);
}
} Ios #include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
@import webview_flutter_wkwebview;
@interface MyWebViewHostApi : FWFWebViewHostApiImpl
// InstanceManager must be weak to prevent a circular reference with the object it stores.
@property(nonatomic, weak) FWFInstanceManager *instanceManager;
@end
@implementation MyWebViewHostApi
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
instanceManager:(FWFInstanceManager *)instanceManager {
self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager];
if (self) {
_instanceManager = instanceManager;
}
return self;
}
- (void)createWithIdentifier:(NSNumber *)identifier configurationIdentifier:(NSNumber *)configurationIdentifier error:(FlutterError * _Nullable __autoreleasing *)error {
[super createWithIdentifier:identifier configurationIdentifier:configurationIdentifier error:error];
WKWebView *webView = (WKWebView *) [self.instanceManager instanceForIdentifier:identifier.longValue];
// Setup WebView for Ads
}
@end
@implementation AppDelegate.m
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
FWFInstanceManager *instanceManager = (FWFInstanceManager *) [self valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"];
NSObject<FlutterPluginRegistrar>* registrar = [self registrarForPlugin:@""];
id<FlutterBinaryMessenger> binaryMessenger = registrar.messenger;
MyWebViewHostApi *webViewHostApi = [[MyWebViewHostApi alloc] initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager];
FWFWKWebViewHostApiSetup(binaryMessenger, webViewHostApi);
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end I will also encourage that you read through https://developers.google.com/ad-manager/mobile-ads-sdk/android/webview and https://developers.google.com/ad-manager/mobile-ads-sdk/ios/webview for full guidelines. |
Sorry for the delayed response. I can confirm that this works on Android Steps followed:
Note: while adding dependencies, resolve versioning issues with gradle, accordingly |
Feature support for the WebView API is still in progress and depends on changes in webview_flutter that will launch in early Q1 2023. The tentative timeline for launching this feature is now early Q1 2022. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi, Can it be confirmed if Flutter Webview Plug-in supports WebView API for ads now? If not still supported please can anyone provide the method to implement it using the Flutter WebView Plugin. Thanks |
@iexpertini - Support for the WebView API for Ads is still in development and planned for a Q1 release this year. If you need to support this API sooner, please check @bparrishMines workaround above. |
Are we there yet? |
I want this on Flutter.
https://support.google.com/admanager/answer/11893859
The text was updated successfully, but these errors were encountered: