Share via


Interstitial ads

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

This walkthrough shows how to include interstitial video ads in Windows 8.1 and Windows Phone 8.1 XAML apps.

Note  Interstitial banner ads are not supported in Windows 8.1 and Windows Phone 8.1 apps.

 

What are interstitial video ads?

Unlike standard banner ads, which are confined to a portion of a UI in an app or game, interstitial video ads are shown on the entire screen. Two basic forms are frequently used in games.

  • With paywall ads, the user must watch an ad at some regular interval. For example, between game levels.
  • With rewards-based ads, the user is explicitly seeking some benefit, such as a hint or extra time to complete the level, and initializes the ad through the app’s user interface.

Note  The API for interstitial ads does not handle any user interface except at the time of video playback. Refer to theinterstitial best practices for guidelines on what to do, and avoid, as you consider how to integrate interstitial ads in your app.

 

Prerequisites

Install the Microsoft Advertising SDK for Windows and Windows Phone 8.x with Visual Studio 2015 or Visual Studio 2013.

Code development

  1. In Visual Studio, open your project or create a new project.

  2. If your project targets Any CPU, update your project to use an architecture-specific build output (for example, x86). If your project targets Any CPU, you will not be able to successfully add a reference to the Microsoft advertising library in the following steps.

  3. From the Solution Explorer window, right click References, and select Add Reference....

  4. In Reference Manager, select one of the following references depending on your project type:

    • For a Windows 8.1 project: Expand Windows 8.1, click Extensions, and then select the check box next to Ad Mediator SDK for Windows 8.1 XAML.
    • For a Windows Phone 8.1 project: Expand Windows Phone 8.1, click Extensions, and then select the check box next to Ad Mediator SDK for Windows Phone 8.1 XAML.
  5. In Reference Manager, click OK.

  6. In the appropriate code file in your app (for example, in MainPage.xaml.cs or a code file for some other page), add the following namespace reference.

    using Microsoft.Advertising.WinRT.UI;
    

    In an appropriate location in your app (for example, in MainPage or some other page), declare an InterstitialAd object and several string fields that represent the application ID and ad unit ID for your interstitial ad. The following code example assigns the myAppId and myAdUnitId fields to the test values for interstitial video ads provided in Set up ad units in your app.

    Note  Every InterstitialAd has a corresponding ad unit that is used by our services to serve ads to the control, and every ad unit consists of an ad unit ID and application ID. In these steps, you assign test ad unit ID and application ID values to your control. These test values can only be used in a test version of your app. Before you publish your app to the Store, you must replace these test values with live values from Windows Dev Center.

     

    InterstitialAd myInterstitialAd = null;
    string myAppId = "d25517cb-12d4-4699-8bdc-52040c712cab";
    string myAdUnitId = "test";
    
  7. In code that runs on startup (for example, in the constructor for the page), instantiate the InterstitialAd object and wire up event handlers for events of the object.

    myInterstitialAd = new InterstitialAd();
    myInterstitialAd.AdReady += MyInterstitialAd_AdReady;
    myInterstitialAd.ErrorOccurred += MyInterstitialAd_ErrorOccurred;
    myInterstitialAd.Completed += MyInterstitialAd_Completed;
    myInterstitialAd.Cancelled += MyInterstitialAd_Cancelled;
    
  8. Approximately 30-60 seconds before you need the ad, use the RequestAd method to pre-fetch the ad. This allows enough time to request and prepare the ad before it should be shown. Be sure to specify AdType.Video for the ad type.

    myInterstitialAd.RequestAd(AdType.Video, myAppId, myAdUnitId);
    
  9. At the point in your code where you want to show the interstitial video ad, confirm that the InterstitialAd is ready to be shown and then show it by using the Show method.

    if (InterstitialAdState.Ready == myInterstitialAd.State)
    {
        myInterstitialAd.Show();
    }
    
  10. Define the event handlers for the InterstitialAd object.

    void MyInterstitialAd_AdReady(object sender, object e)
    {
        // Your code goes here.
    }
    
    void MyInterstitialAd_ErrorOccurred(object sender, AdErrorEventArgs e)
    {
        // Your code goes here.
    }
    
    void MyInterstitialAd_Completed(object sender, object e)
    {
        // Your code goes here.
    }
    
    void MyInterstitialAd_Cancelled(object sender, object e)
    {
        // Your code goes here.
    }
    
  11. Build and test your app to confirm it is showing test ads.

Release your app with live ads using Windows Dev Center

  1. In the Dev Center dashboard, go to the Monetize with ads page for your app and create an ad unit. For the ad unit type, specify Video interstitial. Make note of both the ad unit ID and the application ID.
  2. In your code, replace the test ad unit values with the live values you generated in Dev Center.
  3. Submit your app to the Store using the Dev Center dashboard.
  4. Review your advertising performance reports in the Dev Center dashboard.

Guidelines for interstitial ads

Set up ad units in your app