Embedding advertising into a Windows Phone 8 app with NAX
In this article, we will show an example of the practical use of the Nokia Ad Exchange (NAX) technology based on Inneractive.
.
')
NAX gives you access to the largest ad exchange networks, you only need a PayPal account to receive your money.
Main features of NAX: - Access to over 120 ad networks with a single SDK. - Payments are available in more than 200 countries. - Ability to independently adjust the advertising campaign to promote your application. - Functional advertising control panel. - NAX software developers free.
To start using NAX, you need to register and download the SDK on the page with the development tools for Windows Phone 8.
We strongly recommend that you read the Ad Placement Strategy.html file in the Documentation folder, which discusses options for placing an ad unit. The selected location significantly affects advertising revenue.
Placing an advertisement file in a Windows Phone project
From the InneractiveAdSDK folder of the unpacked SDK, you need to copy the files to the root folder of your Visual Studio project (placement in the root directory is necessary for simplicity, files can be placed and simply in a separate folder): - Inneractive.Ad.dll, - InneractiveAdLocation.cs (this file should be extracted only if you want to use location-based advertising in your WP application).
Then open the Add / Existing Item item in Visual Studio and select both files.
Register Inneractive.Ad.dll
Now register the file Inneractive.Ad.dll. To do this, use the References / Add Reference, then click the Browse button and locate the dll file in the Windows Phone folder. After successfully adding the dll file you will need this link:
If there is an error adding the link “A reference to a project or incompatible assembly cannot be added to the project”, it means that you need to unlock the dll file. To do this, go to the “Security” tab in the file properties and select the “Unblock” option, then “Apply”.
Enable Capabilities
For NAX operation, the necessary capabilities must be enabled in the application. To do this, in the Properties / WMAppManifest.xaml file, check the following check boxes in the Capabilities section:
List of available banner permissions: • 300 x 50 • 320 x 53 • 300 x 250 (Rectangle) • 320 x 480 (Full Screen)
In this example, we add a banner of 320 * 53 pixels at the bottom of the page using the grid. Here is the result:
Nax banner embedded in a Windows Phone app
C # code for NAX
After adding the control to Xaml, you need to write some C # code. To do this, first add two namespaces to the page where the ad will be placed. In this case, this is MainPage.xaml.cs.
using Inneractive.Nokia.Ad; using InneractiveAdLocation;
It is also useful to add the third:
usingMicrosoft.Phone.Net.NetworkInformation;
NetworkInformation is required to check the availability of an Internet connection using the method: DeviceNetworkInformation.IsNetworkAvailable. Then set the optionalParams before the main constructor in the class. All logic in two methods: MainPage_Loaded () and iaLocation_Done ().
public partial class MainPage : PhoneApplicationPage { Dictionary<InneractiveAd.IaOptionalParams, string> optionalParams; // Constructor public MainPage() { InitializeComponent(); // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); } private void MainPage_Loaded(object sender, RoutedEventArgs e) { if (DeviceNetworkInformation.IsNetworkAvailable) { // Watch location IaLocationClass iaLocation = new IaLocationClass(); iaLocation.Done += newSystem.EventHandler<IaLocationEventArgs>(iaLocation_Done); iaLocation.StartWatchLocation(); optionalParams = newDictionary<InneractiveAd.IaOptionalParams, string>(); optionalParams.Add(InneractiveAd.IaOptionalParams.Key_OptionalAdWidth, "320"); //ad width optionalParams.Add(InneractiveAd.IaOptionalParams.Key_OptionalAdHeight, "53"); //add height } //ShowAdd Banner. Remarks: pay attention to use Application Id from NAX if (optionalParams != null) { InneractiveAd iaBanner = new InneractiveAd("ApplicationId", InneractiveAd.IaAdType.IaAdType_Banner, 30, optionalParams); nax_control.Children.Add(iaBanner); } } void iaLocation_Done(object sender, IaLocationEventArgs e) { try { // Addlocation, if received if (e != null && e.location != null) optionalParams.Add(InneractiveAd.IaOptionalParams.Key_Gps_Coordinates, e.location); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error: " + ex.ToString()); } } }
Create AppId
ApplicationId_NAX is generated on the nax.nokia.com site in the Add App item.
You will need to enter the following information: • Mobile platform. • Application Name. • Category. • Whether the application uses location information.
After that, you will get the generated Application Id for your application. This information will be needed to track your ad in the NAX control panel.
Here is the generated AppID that will be used in the application:
Generated AppID that must be specified in the C # code.
That's all. We wish you successful earnings using Nokia NAX ads!