Building the Right Environment to Support AI, Machine Learning and Deep Learning
It is relatively easy for you make money via advertising in your apps. All you need is a valid Windows Store developer license and the Microsoft Advertising SDK. You're not here to read about all my ramblings, so without any further adieu, let us start.
Microsoft Advertising SDK
The Microsoft Advertising SDK is, as its name suggests, a means for us to advertise products in our programs. We can get the advertising SDK here. Download it and install it. It is a very small file (I think just over 1 MB). This will give us a few advertising controls in our toolbox, as displayed in Figure 1.
Figure 1 - Advertising tools
The AdControl is the most common advertising tool found in most Windows 8 Store applications. It is very easy to use and set up. Before I get too far ahead, let us start a quick project and configure it to show ads.
Our program is quite small, and its sole purpose is to get you started with working with ads.
Create a new VB Windows Store Project. If you are not sure how to create a new Windows 8 Store app, have a look at this article I wrote a while back. You could name it anything you like. With this example I have aptly named mine Ads.
Now, we need to reference the Microsoft Advertising SDK. We do this by following the next few steps:
- Click Project, Add Reference
- Inside the Reference Manager window, expand the Windows group
- Inside the Windows group, click Extensions
- Select Microsoft Advertising SDK for Windows 8 (XAML)
- Click OK
You may also need to add the Internet capability to your app, as the ads will get downloaded, fetched from the internet. If this capability does not exist yet, follow these steps to add it:
- Inside Solution Explorer window, double-click the Package.appxmanifest
- Select the Capabilities tab
- Select the Internet Client check box
Now, we can add the AdControl to our form. You can place it anywhere, as this is just an example; but in normal circumstances you'd have a clear idea of where to place the ad. Figure 2 shows the added control to our form.
Figure 2 - The AdControl is added
The following step is to configure this ad control so that it concurs with your customers' needs. We now have to set properties such as Height and Width. A complete XAML code representation of your AdControl might end up looking like this:
<UI:AdControl HorizontalAlignment="Left", Height="357", VerticalAlignment="Top" Width="368", Height="357", AdUnitId="139500", ApplicationId="6907a92c-4800-452a-a425-36b2ef397c22", IsAutoRefreshEnabled="false", Latitude=40.47, Longitude=73.58, AdRefreshed="OnAdRefresh", ErrorOccurred="OnAdError", IsEngagedChanged="OnAdEngagedChanged" />
A couple of interesting properties here! HorizontalAlignment and VerticalAlignment makes sense, as do the Height and Width properties. The rest however seem strange. Let us look at each one of them.
Each ad will have its own unique identifier. This is not simply a random number which I thought up; I obtained this number form Microsoft's PubCenter (which I will explain later in detail). Each AdUnit will have to have its own unique ID. In the above case, this ID was assigned to me.
Just as each AdUnit must have its own identifier, so should each application making use of ads. Again, this Id was assigned to my program via PubCenter.
Enables or disables automatic rotation of ads.
Gets or sets the latitude. Not really necessary when you have set the Horizontal- and VerticalAlignment options
Gets or sets the longitude. Not really necessary when you have set the Horizontal- and VerticalAlignment options
Raised when the AdControl receives a new ad.
Raised when the AdControl encounters an operational error.
Raised when the user clicks the ad and the action dialog box appears.
Now, let us take a good dive into Microsoft PubCenter.
Earlier, I spoke about Microsoft PubCenter assigning an ID to your applications as well as each end every ad. We find the PubCenter here.
Once you are there, you are already halfway!
Register your program by giving it a name. Once that is done you will recive an email confirmation as well as your screen will resemble Figure 3.
Figure 3 - Application confirmation
Now you need to create the ad unit(s) by clicking on Create application ad unit, as displayed in Figure 4.
Figure 4 - Create an ad unit
Fill in the information, such as location as well as the name, as in the next figure.
Figure 5 - Ad Unit details
The final step is to confirm. Again, you will get an email, and your screen should resemble Figure 6.
Figure 6 - Ad Unit Confirmation
The IDs which PubCenter gave our app and our ad or ads must now be used inside the AdControl. Now they are linked.
All that is needed from your side is to include the following events in your app:
Private Sub OnAdRefresh(sender As Object, e As RoutedEventArgs) ''' The code below will print information about the AdRefreshed event to the Debug Output window of Visual Studio Debug.WriteLine(Date.Now.ToString() + " : " + sender.ToString() + " Ad Refreshed.") End Sub Private Sub OnAdError(sender As Object, e As Microsoft.Advertising.WinRT.UI.AdErrorEventArgs) ''' The code below will print information about the ErrorOccurred event to the Debug Output window of Visual Studio Debug.WriteLine(Date.Now.ToString() + " : " + sender.ToString() + " error: " + e.Error.ToString() + " -- " + e.ErrorCode.ToString() + ".") End Sub Private Sub OnAdEngagedChanged(sender As Object, e As RoutedEventArgs) ''' The code below will print information about the EngagedChanged event to the Debug Output window of Visual Studio Debug.WriteLine(Date.Now.ToString() + " : " + sender.ToString() + " EngagedChanged.") End Sub
You can test your ad units by supplying the Test Mode values for your AdControl. This ensures that nothing goes wrong and your ad works as expected
This concludes this introduction. The rest is now up to you to get sponsors for your apps, and I wish you good luck with that! Until next time, cheers!
About the Author:
Hannes du Preez is a Microsoft MVP for Visual Basic for the sixth year in a row. He is a trainer at a South African-based company providing IT training in the Vaal Triangle. You can reach him at hannes [at] ncc-cla [dot] com