Optional Callbacks
The VMAXAdView generates callbacks for successful and unsuccessful fetching attempts of Ads.
Methods
Specifying callbacks in XAML
1 2 3 4 5 6 7 8 9 10 |
<ad:VMAXAdView x:Name="adView" DidCacheAd="AdCached" DidLoadAd="AdReceived" FailedToLoadAd="AdFailed" DidInteractWithAd="InteractedWithAd" WillDismissOverlay="AdCollapsed" WillLeaveApp="LeavingApplication" WillPresentOverlay="AdExpanded" FailedToCacheAd="DidFailed_CacheAd"/> |
Specifying callbacks through Code
1 2 3 4 5 6 7 |
adView.DidLoadAd+=AdReceived; adView.FailedToLoadAd+=AdFailed; adView.DidInteractWithAd+=InteractedWithAd; adView.WillDismissOverlay+=AdCollapsed; adView.WillLeaveApp+=LeavingApplication; adView.WillPresentOverlay+=AdExpanded; adView.FailedToCacheAd+=DidFailed_CacheAd; |
The following methods are used to generate API callbacks.
FailedToLoadAd Callback
The VMAX SDK offers this callback, in cases where an Ad is not served. If required, this event can be used to run any custom code.
1 2 3 4 |
private void AdFailed(object sender, com.vmax.windows.ads.wp8.VMAXAdView.AdFailedEventArgs e) { // ..Custom code goes here } |
FailedToCacheAd Callback
The VMAX SDK offers this callback, in cases where an Ad is not cached. If required, this event can be used to run any custom code.
1 2 3 4 |
private void DidFailed_CacheAd(object sender, EventArgs e) { // … Custom code goes here } |
DidLoadAd Callback
The VMAX SDK offers this callback, in cases where an Ad is rendered successfully. If required, this event can be used to run any custom code.
1 2 3 4 |
private void AdReceived(object sender, EventArgs e) { // ..Custom code goes here } |
DidCacheAd Callback
The VMAX SDK offers this callback, in cases where an Ad is cached successfully. If required, this event can be used to run any custom code.
1 2 3 4 |
private void AdCached(object sender, EventArgs e) { // ..Custom code goes here } |
DidInteractWithAd Callback
The VMAX SDK offers this callback, in cases when you interact with an interstitial/overlay. If required, this event can be used to run any custom code.
1 2 3 4 |
private void AdInteracted(object sender, EventArgs e) { // ..Custom code goes here } |
WillDismissOverlay Callback
The VMAX SDK offers this callback, in cases of an Ad dismissal. If required, this event can be used to run any custom code.
1 2 3 4 |
private void AdCollapsed(object sender, EventArgs e) { // ..Custom code goes here } |
WillLeaveApp Callback
The VMAX SDK offers this callback, in cases of the Ad closing the current App and opening another App. If required, this event can be used to run any custom code.
1 2 3 4 |
private void LeavingApplication(object sender, EventArgs e) { // ..Custom code goes here } |
WillPresentOverlay Callback
The VMAX SDK offers this callback, in cases where an interstitial/overlay is shown. If required, this event can be used to run any custom code.
1 2 3 4 |
private void AdExpanded(object sender, EventArgs e) { // ..Custom code goes here } |
DidRenderNativeAd()
This callback can notify you about the successful rendering of the native ad.
FailedToRenderNativeAd()
You can register for an event FailedToRenderNativeAdwhich can tell you the reason behind the failure in rendering the native ad. One of the reasons can be Empty or Improper JObject being passed to the SetContentAndShowNativeAd() API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
private void InfeedAdControl_FailedToRenderNativeAd(NativeAdEventArgs e) { MessageBox.Show(e.ErrorMessage, "Infeed Ad Control", MessageBoxButton.OK); } private void InfeedAdControl_DidRenderNativeAd() { MessageBox.Show("Infeed ad shown successfully", "Infeed Ad Control",MessageBoxButton.OK); } private void ContentStreamAdControl_FailedToRenderNativeAd(NativeAdEventArgs e) { MessageBox.Show(e.ErrorMessage, "Content Stream Ad Control",MessageBoxButton.OK); } private void ContentStreamAdControl_DidRenderNativeAd() { MessageBox.Show("Content Stream ad shown successfully", "Content Stream Ad Control", MessageBoxButton.OK); } |
The class NativeAdEventArgs contains a field by name ErrorMessage which can tell you the exact reason for the failure in rendering the native ad.
JSON Details
The VMAX Server gives you a JSON that will appear as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{ "BUTTON_LABEL": "Install Now", "ICON_48x48": "sample http image url", "ICON_80x80": "sample http image url", "SCREENSHOT_300x250": "sample http image url", "SPAN_320x50": "sample value", "LARGE_IMAGE_1200x627": "sample http image url", "TITLE_TEXT": "Lost Twins - A Surreal Puzz...", "DESCRIPTION": "Lost Twins is a delightful indie game that is original, beautifully made...", "PRICE": "Free", "TOTAL_INSTALLS": "100", "REVIEW": "sample string", "RATING": "4.1", "SIZE": "2MB", "TOTAL_REVIEWS": "1100", "PRODUCT_CATEGORY": "Action Games", "IMPRESSION_URL": "sample http impression url", "CLICK_URL":”sample http click url” } |
It has several fields out which help in rendering the native ad depending upon the type. The VMAX Sdk also internally gets the same JSON. But it adds more elements to it and creates a new JSON like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
{ "BUTTON_LABEL": "Install Now", "ICON": "sample http image url", "ICON_HEIGHT": "48", "ICON_WIDTH": "48", "SCREENSHOT": "sample http image url", "SCREENSHOT_HEIGHT": "800", "SCREENSHOT_WIDTH": "480", "SPAN": "sample http image url", "SPAN_HEIGHT": "480", "SPAN_WIDTH": "800", "LARGE_IMAGE": "sample http image url", "LARGE_IMAGE_HEIGHT": "1200", "LARGE_IMAGE_WIDTH": "627", "TITLE_TEXT": "Lost Twins - A Surreal Puzz...", "DESCRIPTION": "Lost Twins is a delightful indie game that is original, beautifully...", "PRICE": "Free", "TOTAL_INSTALLS": "100", "REVIEW": "sample string", "RATING": "4.1", "SIZE": "2MB", "TOTAL_REVIEWS": "1100", "PRODUCT_CATEGORY": "Action Games", "IMPRESSION_URL": "sample http impression url", "CLICK_URL": "sample http click url" } |
You can pass any of the above mentioned forms of JSON objects (in a JObject format) to the SetContentAndRenderNativeAd() API and the ad will be rendered according to the type of control used (Infeed or Content Stream).