Vartical Native Ads
Implement callback methods into your “GluedInDelegate“ protocol class.
Step 1: To request ads, use the following method:
		 
		 func requestForAds(feed: FeedModel?, 
                       genre: [String]?,
                       dialect: [String]?,
                       originalLanguage: [String]?,
                       extraParams: [GAMExtraParams]?,
                       adsId: String?,
                       adsFormatId: [String]?) { }
		 
		 
  • feed: The feed model for the ads.
  • genre: Array of genres to target.
  • dialect: Array of dialects to target.
  • originalLanguage: Array of original languages to target.
  • extraParams: Additional parameters for Google Ads Manager.
  • adsId: Unique identifier for the ads.
  • adsFormatId: Array of format IDs for the ads.
Step 2: Request Ads controller on demand basis:
Implement callback methods into your “GluedInDelegate“ protocol class.
To request ads controller on demand basis, use the following method:
		 
		 func getNativeAdController() -> UIViewController? { }
		 
		 
Important method in GADNativeManager class:
Load the Ads:
To load native ads, use the following method, these method is already provided in to sample app, you dont have to change anything there just use as is:
		 
		 func loadNativeAds(
        genre: [String]?,
        dialect: [String]?,
        originalLanguage: [String]?,
        gamExtraParams: [GAMExtraParams]?,
        adUnitID: String?,
        adsFormatId: [String]?,
        didCompeleted: @escaping successHandler,
        didFailedWithError: @escaping errorHandler
    ) {
        self.completed = didCompeleted
        self.failedWithError = didFailedWithError
        self.adsFormatIds = adsFormatId
        self.adLoaderDelegate = self
        GADMobileAds.sharedInstance().audioVideoManager.audioSessionIsApplicationManaged = true
        let videoOptions = GADVideoOptions()
        videoOptions.startMuted = true
        videoOptions.customControlsRequested = true
        self.gadAdLoader = GADAdLoader(
            adUnitID: adUnitID ?? "",
            rootViewController: nil,
            adTypes: [.customNative],
            options: [videoOptions]
        )
        self.gadAdLoader?.delegate = self
        let request = GAMRequest()
        if let customTargetingParams = getExtraAdditionalParameters(
            gamExtraParams: gamExtraParams,
            genre: genre,
            dialect: dialect,
            originalLanguage: originalLanguage
        ) {
            request.customTargeting = customTargetingParams
        }
        self.gadAdLoader?.load(request)
    }
		 
		 
  • genre: Array of genres to target.
  • dialect: Array of dialects to target.
  • originalLanguage: Array of original languages to target.
  • gamExtraParams: Additional parameters for Google Ads Manager.
  • adUnitID: Ad unit ID.
  • adsFormatId: Array of format IDs for the ads.
  • didCompeleted: Completion handler for successful ad load.
  • didFailedWithError: Error handler for failed ad load.
Delegate Ads Method:
Implement the following delegate methods to handle ads:
		 
		 func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) {
        // Handle receiving a native ad
    }
    func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) {
        failedWithError?(error.localizedDescription)
    }
    func adLoaderDidFinishLoading(_ adLoader: GADAdLoader) {
        self.gadAdLoader = nil
        self.adLoaderDelegate = nil
    }
    extension GADNativeManager: GADCustomNativeAdLoaderDelegate {
    func customNativeAdFormatIDs(for adLoader: GADAdLoader) -> [String] {
        return adsFormatIds ?? []
    }
    func adLoader(_ adLoader: GADAdLoader, didReceive customNativeAd: GADCustomNativeAd) {
        completed?(customNativeAd)
    }
}
		 
		 
  • adLoader(_:didReceive:): Handle the event of receiving a native ad.
  • adLoader(_:didFailToReceiveAdWithError:): Handle the event of failing to receive an ad.
  • adLoaderDidFinishLoading(_:): Handle the event of finishing ad loading.
  • customNativeAdFormatIDs(for:): Return the custom native ad format IDs.
  • adLoader(_:didReceive:): Handle the event of receiving a custom native ad.