ms.assetid | description | title | ms.date | ms.topic | keywords | ms.localizationpriority |
---|---|---|---|---|---|---|
646977ed-1705-4ea7-a3db-a6b9aac70703 |
Learn how to launch an interstitial ad using a Universal Windows Platform (UWP) app written in JavaScript and HTML. |
Interstitial ad sample code in JavaScript |
02/18/2020 |
article |
windows 10, uwp, ads, advertising, interstitial, javascript, sample code |
medium |
Warning
As of June 1, 2020, the Microsoft Ad Monetization platform for Windows UWP apps will be shut down. Learn more
This topic provides the complete sample code for a basic JavaScript and HTML Universal Windows Platform (UWP) app that shows an interstitial ad. For step-by-step instructions that show how to configure your project to use this code, see Interstitial ads. For a complete sample project, see the advertising samples on GitHub.
This section shows the contents of the HTML and JavaScript files in a basic app that shows an interstitial ad. To use these examples, copy this code into a JavaScript WinJS App (Universal Windows) project in Visual Studio.
This sample app uses two buttons to request and then launch an interstitial ad. The main.js and index.html files generated by Visual Studio have been modified and are shown below. The script.js file shown below contains most of the code in the sample, and you should add this file to the js folder in your project.
Replace the values of the applicationId
and adUnitId
variables with live values from Partner Center before submitting your app to the Store. For more information, see Set up ad units in your app.
Note
To alter this example to show an interstitial banner ad instead of an interstitial video ad, pass the value InterstitialAdType.display to the first parameter of the RequestAd method instead of InterstitialAdType.video. For more information, see Interstitial ads.
[!div class="tabbedCodeSnippets"] :::code language="html" source="~/../snippets-windows/windows-uwp/monetize/AdvertisingSamples/InterstitialAdSamples/js/index.html" range="1-21":::
[!div class="tabbedCodeSnippets"] :::code language="javascript" source="~/../snippets-windows/windows-uwp/monetize/AdvertisingSamples/InterstitialAdSamples/js/script.js" id="script":::
[!div class="tabbedCodeSnippets"] :::code language="javascript" source="~/../snippets-windows/windows-uwp/monetize/AdvertisingSamples/InterstitialAdSamples/js/main.js" id="main":::