Integrating Microsoft Advertising SDK in Unity - UWP Game


First install Microsoft Advertising SDK. To integrate ad into game, open Package.appxmanifest file in project and ensure Internet (Client) capability is selected. Our project should target specific architecture to make this sdk work.

Add a reference to the Microsoft Advertising SDK in our project:


From the Solution Explorer window, right click References, and select Add Reference…
In Reference Manager, expand Universal Windows, click Extensions, and then select the check box next to Microsoft Advertising SDK for XAML (Version 10.0).
In Reference Manager, click OK.

Modify the XAML for the page where you are embedding advertising to include the Microsoft.Advertising.WinRT.UI namespace. 

<Page
    x:Class="Cortana_Rally_Driver.MainPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Cortana_Rally_Driver"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:UI="using:Microsoft.Advertising.WinRT.UI"
    mc:Ignorable="d"
    Background="#ffffff">
   
   <SwapChainPanel x:Name="DXSwapChainPanel">
    <Grid>
            <UI:AdControl ApplicationId="
applicationid or Store id"
        AdUnitId="
replace it with ad unit id generated in dev center"
        HorizontalAlignment="Center"
      
        Height="90"
        VerticalAlignment="Top"
        Width="728"/>
        </Grid>
   
    </SwapChainPanel>
</Page>

Comments

Popular Posts