flutter_google_ad_manager icon indicating copy to clipboard operation
flutter_google_ad_manager copied to clipboard

Feature/Custom Native Ads integration

Open el12n opened this issue 4 years ago • 0 comments

Overview

Implemented Custom Native Ad.

Custom Native Ads

Firstly load it at the desired timing.

DFPNativeAd _nativeAd;

@override
  void initState() {
    super.initState();
    _nativeAd = DFPNativeAd(
      isDevelop: false,
      adUnitId: "XXXXXXXX",
      templateId: "XXXXXXXX",
      onAdLoaded: () async {
        print('nativeAd onAdLoaded');
      },
      onAdFailedToLoad: (errorCode) {
        print('nativeAd onAdFailedToLoad: errorCode:$errorCode');
      },
      onAdOpened: () {
        print('nativeAd onAdOpened');
      },
      onAdClosed: () {
        print('nativeAd onAdClosed');
      },
      onAdLeftApplication: () {
        print('nativeAd onAdLeftApplication');
      },
    );
    _nativeAd.load();
  }

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

Then after make sure the _nativeAd called the onAdLoaded callback it is ready to use you can safe call theses methods.

//To request the asset for the variable name
await _nativeAd.getParameter(DFPNativeAdParameterType.image, "AssetName");
//To perform the default action over that asset 
_nativeAd.performClickAction("AssetName");

More info

  • https://developers.google.com/ad-manager/mobile-ads-sdk/ios/native/custom-formats
  • https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/custom-formats

el12n avatar Nov 25 '20 18:11 el12n