Asked by:
[UWP] [C#] Desktop / Mobile advertisement block switching best practice ?

Question
-
There are two type for creating advertisement unit
1. for mobile
2. for PC / tablet
Also there are two main group for advertisement block size here
https://msdn.microsoft.com/en-us/windows/uwp/monetize/supported-ad-sizes-for-banner-ads
for PC and for Mobile.
My application can be runned on Mobile and on PC.
If I will use Mobile advertisement size everytwhere - it will be very small for PC.
And may be I will have less result as can.
If I will use PC advertisement size everytwhere - it will be very large for Mobile.
What is the best practice for this situation ?
- Moved by Xavier Xie-MSFT Wednesday, November 23, 2016 3:01 AM
All replies
-
In height x width, if a typical phone screen is 800 x 480, then the only new UWP(10) SDK supported size that will work on phones is 300x250, as the other supported sizes are too wide for an ad of their size to be displayed.
Thus the ad will fill almost half of the app's screen vertically when run on a typical phone, AND when centered at top or bottom of the screen (as is typical, I think), there will be considerable wasted blank space on either side of the ad as well.
Am I thinking of this correctly? And if so, how can this work for apps that are trying to already display useful information in small spaces on phones?
Gary Glanz
- Merged by Cherry BuMicrosoft contingent staff, Moderator Tuesday, December 6, 2016 9:01 AM same issue
-
Hi GaryGlanz,
Form supported ad sizes for banner ads, we could see that there are some sizes for Windows 10 Mobile and Windows Phone 8.x. If you want to add ad in your UWP project and your application will work on Phone, I suggest you to choose these sizes.
If you choose sizes for Windows 10(UWP) and Windows 8.1, although the ad will still work fine on your UWP project, the width and height of the ad is quite mismatched with the Phone screen.
If you want your application work on desktop, Phone, you could follow the above screenshot. First please judge whether it is Phone or desktop platform by using EasClientDeviceInformation class.AdControladcontrol = newAdControl();
publicMainPage()
{
this.InitializeComponent();
}
privatevoidAdcontrol_AdRefreshed(objectsender, RoutedEventArgse)
{
}
privatevoidAdcontrol_ErrorOccurred(objectsender, AdErrorEventArgse)
{
Debug.WriteLine(e.ErrorMessage);
}
privatevoidCreateAd_Click(objectsender, RoutedEventArgse)
{
varclientDeviceInformation = newEasClientDeviceInformation();
varoperatingSystem = clientDeviceInformation.OperatingSystem;
if(operatingSystem.Equals("WINDOWS"))
{
varbutton = (Button)sender;
button.IsEnabled =
false;
adcontrol.ApplicationId =
"3f83fe91-d6be-434d-a0ae-7351c5a997f1";
adcontrol.AdUnitId =
"10865270";
adcontrol.Width = 300;
adcontrol.Height = 250;
adcontrol.ErrorOccurred += Adcontrol_ErrorOccurred;
adcontrol.AdRefreshed += Adcontrol_AdRefreshed;
varparent = (Panel)button.Parent;
parent.Children.Add(adcontrol);
}
else
{
varbutton = (Button)sender;
button.IsEnabled =
false;
adcontrol.ApplicationId =
"3f83fe91-d6be-434d-a0ae-7351c5a997f1";
adcontrol.AdUnitId =
"10865270";
adcontrol.Width = 300;
adcontrol.Height = 50;
adcontrol.ErrorOccurred += Adcontrol_ErrorOccurred;
adcontrol.AdRefreshed += Adcontrol_AdRefreshed;
varparent = (Panel)button.Parent;
parent.Children.Add(adcontrol);
}
}
Best Regards,
Cherry Bu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- Proposed as answer by Cherry BuMicrosoft contingent staff, Moderator Friday, November 18, 2016 1:22 AM
- Edited by Cherry BuMicrosoft contingent staff, Moderator Wednesday, November 23, 2016 5:24 AM
-
Hi SmartWhy,
Based on your description, you want to add correct size ads in your UWP project.
Firstly, in the Dashboard, you should create two kinds of AdUnits, for PC/tablet and Mobile. The screenshot you can refer to.Then you could need to judge whether it is Phone or desktop platform by using EasClientDeviceInformation class.
AdControl adcontrol = new AdControl();
public MainPage()
{
this.InitializeComponent();
}
private void Adcontrol_AdRefreshed(object sender, RoutedEventArgs e)
{
}
private void Adcontrol_ErrorOccurred(object sender, AdErrorEventArgs e)
{
Debug.WriteLine(e.ErrorMessage);
}
private void CreateAd_Click(object sender, RoutedEventArgs e)
{
var clientDeviceInformation = new EasClientDeviceInformation();
var operatingSystem = clientDeviceInformation.OperatingSystem;
if (operatingSystem.Equals("WINDOWS"))
{
var button = (Button)sender;
button.IsEnabled = false;
adcontrol.ApplicationId = "3f83fe91-d6be-434d-a0ae-7351c5a997f1";
adcontrol.AdUnitId = "10865270";
adcontrol.Width = 300;
adcontrol.Height = 250;
adcontrol.ErrorOccurred += Adcontrol_ErrorOccurred;
adcontrol.AdRefreshed += Adcontrol_AdRefreshed;
var parent = (Panel)button.Parent;
parent.Children.Add(adcontrol);
}
else
{
var button = (Button)sender;
button.IsEnabled = false;
adcontrol.ApplicationId = "3f83fe91-d6be-434d-a0ae-7351c5a997f1";
adcontrol.AdUnitId = "10865270";
adcontrol.Width = 300;
adcontrol.Height = 50;
adcontrol.ErrorOccurred += Adcontrol_ErrorOccurred;
adcontrol.AdRefreshed += Adcontrol_AdRefreshed;
var parent = (Panel)button.Parent;
parent.Children.Add(adcontrol);
}
}
Please note supported ad sizes for banner ads.
Best Regards,
Cherry BuMSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- Proposed as answer by Cherry BuMicrosoft contingent staff, Moderator Wednesday, November 23, 2016 8:09 AM
-
Hi SmartWhy,
Are you trying the solution I provided? Please let me know whether it works fine or not.
Thank you.
Best Regards,
Cherry Bu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
-