# Interstitial Ads

Interstitials are either static or video ads presented before, during or after the user interacts with your app. The user can view and then immediately dismiss them. This is a non-rewarded format for the user.

{% hint style="info" %}
The speed and stability of a user's internet connections may vary. It is highly recommended to fetch as much in advance of showing an ad as possible. This helps to ensure that all necessary assets are downloaded. For example, you may want to fetch an ad when a level starts or after a previous ad has been shown.
{% endhint %}

### Making the Request

Below is an example of making a request for an Intersitial.

{% tabs %}
{% tab title="Android" %}
{% code title="Kotlin" %}

```kotlin
import com.fyber.fairbid.ads.Interstitial

val placementId = "12345"
Interstitial.request(placementId)
```

{% endcode %}

{% code title="Java" %}

```java
import com.fyber.fairbid.ads.Interstitial;

String placementId = "12345";
Interstitial.request(placementId);
```

{% endcode %}
{% endtab %}

{% tab title="iOS" %}
{% code title="Swift" %}

```swift
FYBInterstitial.delegate = MyInterstitialDelegate()
let placementId = "1234"
FYBInterstitial.request(placementId)
```

{% endcode %}

{% code title="Objective-C" %}

```objective-c
#import <FairBidSDK/FairBid.h>
FYBInterstitial.delegate = [[MyInterstitialDelegate alloc] init];
NSString *placementId = @"1234";
[FYBInterstitial request:placementId];
```

{% endcode %}
{% endtab %}

{% tab title="Unity" %}
{% code title="C#" %}

```csharp
string placementId = "1234";
Interstitial.Request(placementId);
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Adding Callbacks

The callback code below is required for the SDK to properly track the activity of your ad

{% tabs %}
{% tab title="Android" %}
{% code title="Kotlin" %}

```kotlin
Interstitial.setInterstitialListener(object : InterstitialListener {
    override fun onShow(placementId: String, impressionData: ImpressionData) {
        // Called when the interstitial from placement 'placementId' shows up.
        // In case the ad is a video, audio play will start here.
    }

    override fun onClick(placementId: String) {
        // Called when the interstitial from placement 'placementId' is clicked
    }

    override fun onHide(placementId: String) {
        // Called when the interstitial from placement 'placementId' hides.
        // In case the ad is a video, audio play will stop here.
    }

    override fun onShowFailure(placementId: String, impressionData: ImpressionData) {
        // Called when an error arises when showing the interstitial from placement 'placementId'
    }

    override fun onAvailable(placementId: String) {
        // Called when an interstitial from placement 'placementId' becomes available
    }

    override fun onUnavailable(placementId: String) {
        // Called when an interstitial from placement 'placementId' becomes unavailable
    }

    override fun onRequestStart(placementId: String, requestId: String) {
        // Called when an interstitial from placement 'placementId' is going to be requested
        // 'requestId' identifies the request across the whole request/show flow
    }
})
```

{% endcode %}

{% code title="Java" %}

```java
Interstitial.setInterstitialListener(new InterstitialListener() {
    @Override
    public void onShow(String placementId, ImpressionData impressionData) {
        // Called when the interstitial from placement 'placementId' shows up.
        // In case the ad is a video, audio play will start here.
    }

    @Override
    public void onClick(String placementId) {
        // Called when the interstitial from placement 'placementId' is clicked
    }

    @Override
    public void onHide(String placementId) {
        // Called when the interstitial from placement 'placementId' hides.
        // In case the ad is a video, audio play will stop here.
    }

    @Override
    public void onShowFailure(String placementId, ImpressionData impressionData) {
        // Called when an error arises when showing the interstitial from placement 'placementId'
    }

    @Override
    public void onAvailable(String placementId) {
        // Called when a interstitial from placement 'placementId' becomes available
    }

    @Override
    public void onUnavailable(String placementId) {
        // Called when a interstitial from placement 'placementId' becomes unavailable
    }

  	@Override
    public void onRequestStart(String placementId, String requestId) {
        // Called when a interstitial from placement 'placementId' is going to be requested
        // 'requestId' identifies the request across the whole request/show flow
    }
});
```

{% endcode %}
{% endtab %}

{% tab title="iOS" %}
{% code title="Swift" %}

```swift
class MyInterstitialDelegate: NSObject, FYBInterstitialDelegate {

    func interstitialIsAvailable(_ placementId: String) {}

    func interstitialIsUnavailable(_ placementId: String) {}

    func interstitialDidShow(_ placementId: String, impressionData: FYBImpressionData) {}

    func interstitialDidFail(toShow placementId: String, withError error: Error, impressionData: FYBImpressionData) {}

    func interstitialDidClick(_ placementId: String) {}

    func interstitialDidDismiss(_ placementId: String) {}

    func interstitialWillRequest(_ placementId: String, withRequestId requestId: String) {}

}
```

{% endcode %}

{% code title="Objective-C" %}

```objective-c
#import <FairBidSDK/FairBid.h>

@interface MyInterstitialDelegate : NSObject

@end

@implementation MyInterstitialDelegate

- (void)interstitialIsAvailable:(NSString *)placementId {
//    Called when an Interstitial from placement becomes available
}

- (void)interstitialIsUnavailable:(NSString *)placementId {
//    Called when an Interstitial from placement becomes unavailable
}

- (void)interstitialDidShow:(NSString *)placementId impressionData:(FYBImpressionData *)impressionData {
//    Called when an Interstitial from placement shows up.
//    In case the ad is a video, audio play will start here.
}

- (void)interstitialDidFailToShow:(NSString *)placementId withError:(NSError *)error impressionData:(FYBImpressionData *)impressionData {
//    Called when an error arises when showing an Interstitial from placement
}

- (void)interstitialDidClick:(NSString *)placementId {
//    Called when an Interstitial from placement is clicked
}

- (void)interstitialDidDismiss:(NSString *)placementId {
//    Called when an Interstitial from placement hides.
//    In case the ad is a video, audio play will stop here.
}

- (void)interstitialWillRequest:(NSString *)placementId withRequestId:(NSString *)requestId {
//    Called when an Interstitial is going to be requested.
}

@end.
```

{% endcode %}
{% endtab %}

{% tab title="Unity" %}
{% code title="C#" %}

```csharp
public class MyInterstitialListener : InterstitialListener
{

    public void OnShow(string placementId, ImpressionData impressionData)
    {
        // Called when an Interstitial from placement 'placementId' shows up.
        // In case the ad is a video, audio play will start here.
        // On Android, this callback might be called only once the ad is closed.
    }

    public void OnClick(string placementId)
    {
        // Called when an Interstitial from placement 'placementId' is clicked
    }

    public void OnHide(string placementId)
    {
        // Called when an Interstitial from placement 'placementId' hides.
    }

    public void OnShowFailure(string placementId, ImpressionData impressionData)
    {
        // Called when an error arises when showing an Interstitial from placement 'placementId'
    }

    public void OnAvailable(string placementId)
    {
        // Called when an Interstitial from placement 'placementId' becomes available
    }

    public void OnUnavailable(string placementId)
    {
        // Called when an Interstitial from placement 'placementId' becomes unavailable
    }

    public void OnRequestStart(string placementId)
    {
        // Called when an Interstitial from placement 'placementId' is going to be requested
    }
}

Interstitial.SetInterstitialListener(new MyInterstitialListener());
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Example Showing an Ad

The following example checks to see if a Placement is available and if it is, uses the show request to display the ad.

{% tabs %}
{% tab title="Android" %}
{% code title="Kotlin" %}

```kotlin
val placementId = "12345"
if (Interstitial.isAvailable(placementId)) {
    Interstitial.show(placementId, context)
}
```

{% endcode %}

{% code title="Java" %}

```java
String placementId = "12345";
if (Interstitial.isAvailable(placementId)) {
    Interstitial.show(placementId, context);
}
```

{% endcode %}
{% endtab %}

{% tab title="iOS" %}
{% code title="Swift" %}

```swift
let placementId = "1234"
if (FYBInterstitial.isAvailable(placementId)) {
    FYBInterstitial.show("placementId")
}
if (FYBInterstitial.isAvailable(placementId)) {
    let showOptions = FYBShowOptions()
    showOptions.viewController = self.myViewController
    FYBInterstitial.show(placementId, options: showOptions)
}
```

{% endcode %}

{% code title="Objective-C" %}

```objective-c
NSString *placementId = @"1234";
if ([FYBInterstitial isAvailable:placementId]) {
    [FYBInterstitial show:placementId];
}

if ([FYBInterstitial isAvailable:placementId]) {
    FYBShowOptions *showOptions = [FYBShowOptions new];
    showOptions.viewController = self.myViewController;
    [FYBInterstitial show:placementId options:showOptions];
}swif
```

{% endcode %}
{% endtab %}

{% tab title="Unity" %}
{% hint style="warning" %}
If your game needs to be paused before showing an ad (e.g., stop audio playback), this is the best moment to do so.

The time between calling this API and the ad actually being shown should be negligible.

This approached is preferable compared to relying on the 'OnShow' callback since on Android, we cannot guarantee it will be called before the ad starts playing.
{% endhint %}

{% code title="C#" %}

```csharp
string placementId = "1234";

if (Interstitial.IsAvailable(placementId)) {
	Interstitial.Show(placementId);
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
