# Native (Google)

The native ads are a kind of ad that can be shown using the same visual style like the rest of the app, which allows a natural and non-intrusive integration with the user interface.

Currently, Wortise provides the possibility of use the native ads from Google's ad platform ("*Native Advanced*"), in a simple and direct way.

## Integration

To request a native ad, it is needed to make an integration by code just as shown in the example below:

{% tabs %}
{% tab title="Swift" %}

```swift
import UIKit
import WortiseSDK

class ViewController: UIViewController {
    private var nativeAd: WAGoogleNativeAd!

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        nativeAd = WAGoogleNativeAd(adUnitId: "test-native",
                                    rootViewController: self,
                                    delegate: self)
        nativeAd.loadAd()
    }

    override func willMove(toParent controller: UIViewController?) {
        super.willMove(toParent: controller)
        ...
        nativeAd.destroy()
    }
}

extension ViewController: WAGoogleNativeDelegate {

    func didClick(nativeAd: WAGoogleNativeAd) {
        // Invoked when the ad has been clicked
    }

    func didFailToLoad(nativeAd: WAGoogleNativeAd, error: WAAdError) {
        // Invoked when the ad could not be loaded
        // (because of an error or no fill)
    }

    func didLoad(nativeAd: WAGoogleNativeAd, googleNativeAd: GADNativeAd) {
        // Invoked when the ad has been loaded
    }
    
    func didPayRevenue(nativeAd: WAGoogleNativeAd, data: WARevenuedata) {
        // Invoked when the ad has generated revenue
    }

    func didRecord(impression: WAGoogleNativeAd) {
        // Invoked when the ad has generated an impression
    }
}
```

{% endtab %}
{% endtabs %}

Once the native ad has been successfully loaded, obtaining as result a `GADNativeAd` instance, it is needed to complete the integration by following Google's documentation on this matter: <https://developers.google.com/ad-manager/mobile-ads-sdk/ios/native/advanced?hl=en#display_a_nativead>

### Specify options

The `WAGoogleNativeAd` class includes an attribute called `options` which allows to specify custom options by using the `GADAdLoaderOptions` class from Google. This attribute must be set before loading the ad.

Below you can check a brief usage example:

{% tabs %}
{% tab title="Swift" %}

```swift
let adOptions = GADNativeAdViewAdOptions()

// Set the options through "adOptions"

googleNativeAd.options = adOptions
```

{% endtab %}
{% endtabs %}
