# App Open

## Integration

Below we show a few simple examples to implement the App Open ads by following the two possible ways of integration:

### Manual

```dart
import 'package:wortise/app_open_ad.dart';

AppOpenAd _appOpenAd;

// Create an App Open
_appOpenAd = AppOpenAd('Wortise Ad Unit ID', listener: (event, args) {
  // This listener will be invoked when an event happens
});

// Request an ad
await _appOpenAd.loadAd();

/* ... */

// Show the ad if available
if (await _appOpenAd.isAvailable) {
  await _appOpenAd.showAd();
}
```

The AppOpenAd class constructor allows to specify the following optional parameters to configure its behaviour:

```dart
// Sets if a new ad must be loaded after closing the previous one
autoReload: true
```

Alternatively, the `tryToShowAd()` method can be used to show the ad with the difference that, if there is none available, the load of a new ad is automatically requested.

```dart
await _appOpenAd.tryToShowAd();
```

### Via Manager

```dart
import 'package:wortise/app_open_ad.dart';
import 'package:wortise/app_open_manager.dart';

// Create an App Open
AppOpenAd appOpenAd = AppOpenAd('Wortise Ad Unit ID')..loadAd();

// Register the ad in the manager
AppOpenManager.register(appOpenAd);
```

In this integration, the ads will be automatically shown when an app transitions from background to foreground. Also, the methods offered by `AppOpenAd` can still be used to show ads on demand.

## **Listener events**

The assigned listener to an `AppOpenAd` can receive the following events:

```dart
// The ad has been clicked
AppOpenAdEvent.CLICKED
// The ad has been dismissed
AppOpenAdEvent.DISMISSED
// The ad could not be loaded
AppOpenAdEvent.FAILED_TO_LOAD
// The ad could not be shown
AppOpenAdEvent.FAILED_TO_SHOW
// The ad has generated an impression
AppOpenAdEvent.IMPRESSION
// The ad has been loaded
AppOpenAdEvent.LOADED
// The ad has generated revenue
AppOpenAdEvent.REVENUE_PAID
// The ad has been shown
AppOpenAdEvent.SHOWN
```
