googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
343 stars 285 forks source link

FAN native banner ads are not clickable in mediation. #175

Closed arunchaudharyweb closed 3 years ago

arunchaudharyweb commented 3 years ago

I am using FAN and admob in my application. I have followed all the steps mentioned here. The mediation is working fine. Native ads are loading from FAN. I followed this documentation to display native ads. Now admob native advanced ads are clickable when clicked on ad headline or app icon but nothing happens when I click on FAN native banner ads.

arunchaudharyweb commented 3 years ago

Mopub native ads are also clickable. Only FAN ads are not clickable. I am using google_mobile_ads 0.13.0.

jjliu15 commented 3 years ago

Could you share a code sample of your dart and Android code for creating the native ad?

arunchaudharyweb commented 3 years ago

This is my dart code.

class HomePageBottomBar extends StatefulWidget {
  @override
  _HomePageBottomBarState createState() => _HomePageBottomBarState();
}

class _HomePageBottomBarState extends State<HomePageBottomBar> {
  NativeAd? _nativeAd;
  ValueNotifier<bool> _adLoaded = ValueNotifier<bool>(false);
  Future<void> _createNativeBanner() async {
    final NativeAd _native = NativeAd(
      factoryId: 'bottomBar',
      request: AdRequest(),
      adUnitId: 'ca-app-pub-44031011871XXXXXXXXXXXX',
      listener: NativeAdListener(
        onAdLoaded: (Ad ad) {
          print('$NativeAd loaded.');
          _nativeAd = ad as NativeAd?;
          _adLoaded.value = true;
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          print('$NativeAd failedToLoad: $error');
          ad.dispose();
        },
      ),
    );
    return _native.load();
  }

  @override
  void initState() {
    _createNativeBanner();
    super.initState();
  }

  @override
  void dispose() {
    _nativeAd?.dispose();
    _adLoaded.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder(
      valueListenable: _adLoaded,
      builder: (context, value, child) {
        return Container(
          decoration: BoxDecoration(
              color: kBottomBarColor,
              border: Border.all(color: kContainerColor)),
          height: 62,
          child: _adLoaded.value && _nativeAd != null
              ? AdWidget(ad: _nativeAd!)
              : Center(
                  child: Text(
                  AppLocalizations.of(context)!.adSpace,
                  style: TextStyle(color: Color(0xffA9A9A9)),
                )),
        );
      },
    );
  }
}

This is my java code.

import com.google.android.gms.ads.nativead.NativeAd;
import com.google.android.gms.ads.nativead.NativeAdView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.Map;

import io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.NativeAdFactory;

class NativeAdFile implements NativeAdFactory {

    private final LayoutInflater layoutInflater;
    private final boolean isBottom;

    NativeAdFile(LayoutInflater layoutInflater, boolean isBottom ) {
        this.layoutInflater = layoutInflater;
        this.isBottom = isBottom;
    }

    @Override
    public NativeAdView createNativeAd(
            NativeAd nativeAd, Map<String, Object> customOptions) {
        NativeAdView adView;
        if(isBottom){
            adView = (NativeAdView) layoutInflater.inflate(R.layout.bottom_bar, null);
        } else {
            adView = (NativeAdView) layoutInflater.inflate(R.layout.list_tile_native_ad, null);
        }

        adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
        adView.setBodyView(adView.findViewById(R.id.ad_body));
        adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
        adView.setIconView(adView.findViewById(R.id.ad_app_icon));

        ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());

        if (nativeAd.getBody() == null) {
            adView.getBodyView().setVisibility(View.INVISIBLE);
        } else {
            adView.getBodyView().setVisibility(View.VISIBLE);
            ((TextView) adView.getBodyView()).setText(nativeAd.getBody());

        }

        if (nativeAd.getCallToAction() == null) {
            adView.getCallToActionView().setVisibility(View.INVISIBLE);
        } else {
            adView.getCallToActionView().setVisibility(View.VISIBLE);
            ((TextView) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
        }

        if (nativeAd.getIcon() == null) {
            adView.getIconView().setVisibility(View.GONE);
        } else {
            adView.getIconView().setVisibility(View.VISIBLE);
            ((ImageView) adView.getIconView()).setImageDrawable(nativeAd.getIcon().getDrawable());
        }

        adView.setNativeAd(nativeAd);

        return adView;
    }
}
jjliu15 commented 3 years ago

I think the issue lies in your NativeAdFactory implementation. I'm able to reproduce the issue when I copy your implementation into the NativeAdFactory in the example app.

Can you try adding the following line to the top of NativeAdFactory. createNativeAd()?

    adView.setMediaView((MediaView) adView.findViewById(R.id.ad_media));

I'd suggest also taking a look at the example NativeAdFactory as a reference.

arunchaudharyweb commented 3 years ago

It works. But I don't want to show media content in my native ad.

jjliu15 commented 3 years ago

According to FAN documentation, you are required to use media view for native ads: https://developers.facebook.com/docs/audience-network/guides/ad-formats/native/#mediaview

arunchaudharyweb commented 3 years ago

I tried it with the official Admob SDK for Android. FAN native advanced are clickable there without using MediaView in mediation. It seems that the issue is in Flutter Admob SDK.

arunchaudharyweb commented 3 years ago

Screenshot (152) Facebook told me that there was no need to use MediaView in native banner ads. It's clearly a bug in this plugin so please reopen this issue.

Vakil-Parth commented 3 years ago

no update?

Vakil-Parth commented 3 years ago

It started working after updating mediation plugin, implementation 'com.google.ads.mediation:facebook:6.6.0.0'

yashb042 commented 3 years ago

I am using the latest mediation plugin implementation 'com.google.ads.mediation:facebook:6.6.0.0'

Still not able to click the native ads. Should I try downgrading the plugin. If yes, to which version.

@Vakil-Parth

@arunchaudharyweb I also tried using media view as suggested by some comments. I am using native ads in a list and would need the xml for that (I'm not strong with the view part). Posting my current xml file

`<?xml version="1.0" encoding="utf-8"?> <com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_list_tile_native_ad_attribution_small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#F19938"
        android:text="Ad"
        android:textColor="#FFFFFF"
        android:textSize="12sp" />

    <ImageView
        android:id="@+id/iv_list_tile_native_ad_icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:scaleType="fitXY"
        tools:background="#EDEDED" />

    <TextView
        android:id="@+id/tv_list_tile_native_ad_attribution_large"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:background="#F19938"
        android:gravity="center"
        android:text="Ad"
        android:textColor="#FFFFFF"
        android:visibility="invisible" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="80dp"
        android:layout_marginLeft="80dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_list_tile_native_ad_headline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:lines="1"
            android:maxLines="1"
            android:textColor="#FFFFFFFF"
            android:textSize="16sp"
            tools:text="Headline" />

        <TextView
            android:id="@+id/tv_list_tile_native_ad_body"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:lines="1"
            android:maxLines="1"
            android:textColor="#62FFFFFF"
            android:textSize="14sp"
            tools:text="body" />

    </LinearLayout>

</FrameLayout>

</com.google.android.gms.ads.nativead.NativeAdView>`

renolation commented 2 years ago

any update?

pritampawade commented 2 years ago

I am also facing the same issue