一:前提條件
1:將KeyMob與應用集成。
2:您可能還須要先了解發送AdRequest的相關信息以及中介的工做原理。
二:橫幅廣告自定義事件
在如下示例中,您將首先在KeyMob中介內建立一個橫幅廣告自定義事件。這須要經過KeyMob界面定義一個自定義事件,指向您應用中的特定類,而後實現自定義事件橫幅廣告以投放視圖。
三:定義自定義事件
自定義事件必須在 KeyMob界面中進行定義。您能夠在此幫助中心指南中找到爲特定廣告單元修改中介的說明。
如下是自定義事件示例的部分設置:
Label:AdMobCustomEvent
Class Name:CustomAd
Parameter:a1401234567890
要定義自定義事件,您僅需提供類的名稱做爲類名稱便可。參數應該包含全部必需的信息,以便向廣告網絡發送您在自定義事件中實現的廣告請求。在這種狀況下,KeyMob自定義事件僅須要發佈商ID。
四:請求橫幅廣告
定義名爲CustomAd的類,它表示在您的自定義事件設置中定義的類名稱。它應該實現GADCustomEventBanner。當系統從中介廣告瀑布流中選擇自定義事件後,KeyMob中介 SDK 會針對您在設置中提供的類名稱調用requestBannerAd方法。您可使用此方法提供的參數向您所需的廣告網絡發送橫幅廣告請求。如下示例向 KeyMob發出了請求。
1:CustomAd.h
@import GoogleMobileAds;
@interface CustomAd:NSObject<GADCustomEventBanner,GADBannerViewDelegate> {
GADBannerView *bannerView_;
}
@end
2:CustomAd.m
#import "CustomAd.h"
@implementation CustomAd
// Will be set by the Mobile Ads SDK.
@synthesize delegate;
- (void)dealloc {
bannerView_.delegate = nil;
[bannerView_ release];
[super dealloc];
}
#pragma mark -
#pragma mark GADCustomEventBanner
- (void)requestBannerAd:(GADAdSize)adSize
parameter:(NSString *)serverParameter
label:(NSString *)serverLabel
request:(GADCustomEventRequest *)customEventRequest {
// Create the bannerView with the appropriate size.
self.bannerView = [[GADBannerView alloc] initWithAdSize:adSize];
// Set the delegate to listen for callbacks.
self.bannerView.delegate = self;
// Set the publisher ID for the banner. This comes from server parameter
// you provide when creating the custom event in mediation.
self.bannerView.adUnitID = serverParameter;
// Let the bannerView know which UIViewController to restore after returning
// from and ad click. The UIViewController is available from
// GADCustomEventBannerDelegate.
self.bannerView.rootViewController=[self.delegate viewControllerForPresentingModalView ];
// Create an ad request using custom targeting options from the custom event
// request
GADRequest *request = [GADRequest request];
[request setAdditionalParameters:[customEventRequest additionalParameters]];
[request setBirthday:[customEventRequest userBirthday]];
[request setGender:[customEventRequest userGender]];
[request setTesting:[customEventRequest isTesting]];
if ([customEventRequest userHasLocation]) {
[request setLocationWithLatitude:[customEventRequest userLatitude]
longitude:[customEventRequest userLongitude]
accuracy:[customEventRequest userLocationAccuracyInMeters]];
}
[self.bannerView loadRequest:request];
}
自定義事件必須在成功收到廣告或沒法收到廣告時,經過GADCustomEventBanner通知中介 SDK。不然,自定義事件會超時,中介會繼續聯繫下一個廣告網絡。
五:通知 KeyMob中介
爲您的廣告網絡實施廣告監聽器並調用GADCustomEventBanner上的相關回調,以將消息發回給中介。如下示例會實施KeyMob的GADBannerViewDelegate接口,以發送這些消息。
#pragma mark -
#pragma mark GADBannerView Callbacks
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
[self.delegate customEventBanner:self didReceiveAd:adView];
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(NSError *)error {
[self.delegate customEventBanner:self didFailAd:error];
}
- (void)adViewWillPresentScreen:(GADBannerView *)adView {
[self.delegate customEventBanner:self clickDidOccurInAd:adView];
[self.delegate customEventBannerWillPresentModal:self];
}
- (void)adViewWillDismissScreen:(GADBannerView *)adView {
[self.delegate customEventBannerWillDismissModal:self];
}
- (void)adViewDidDismissScreen:(GADBannerView *)adView {
[self.delegate customEventBannerDidDismissModal:self];
}
- (void)adViewWillLeaveApplication:(GADBannerView *)adView {
[self.delegate customEventBannerWillLeaveApplication:self];
}
@end
注意:您必須將全部的回調都通知中介。
您的自定義事件至少應調用GADCustomEventBanner中的如下三種回調:
customEventBanner:didReceiveAd:中介能夠展現傳遞給它的廣告。沒法調用此回調會致使超時,從而使中介繼續聯繫下一個廣告網絡。
customEventBanner:didFailAd:中介能夠繼續從中介廣告瀑布流中的下一個廣告網絡中請求廣告,而沒必要等待超時。
customEventBanner:clickDidOccurInAd:讓中介記錄並報告您的自定義事件收到的點擊次數。
五:插頁式廣告自定義事件
插頁式廣告自定義事件的實現方法與橫幅廣告自定義事件的實現方法相似。二者的主要區別是:您建立的插頁式廣告自定義事件類應該實現GADCustomEventInterstitial接口(而不是GADCustomEventBanner)。
六:請求插頁式廣告
如下示例介紹了經過自定義事件請求KeyMob 插頁式廣告的方法:
1:CustomAd.h
@import GoogleMobileAds;
@interface CustomAd:NSObject<GADCustomEventInterstitial,GADInterstitialDelegate> {
GADInterstitial *interstitial_;
}
@end
2:CustomAd.m
#import "CustomAd.h"
@implementation CustomAd
// Will be set by the Mobile Ads SDK.
@synthesize delegate;
- (void)dealloc {
interstitial_.delegate = nil;
[interstitial_ release];
[super dealloc];
}
#pragma mark -
#pragma mark GADCustomEventInterstitial
- (void)requestInterstitialAdWithParameter:(NSString *)serverParameter
label:(NSString *)serverLabel
request:(GADCustomEventRequest *)customEventRequest {
// Set the publisher ID for the interstitial. The ID comes from the server
// parameter you provide when creating the custom event.
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:serverParameter];
// Set the delegate to listen for callbacks.
self.interstitial.delegate = self;
// Create an ad request using custom targeting options from the custom event
// request.
GADRequest *request = [GADRequest request];
[request setAdditionalParameters:[customEventRequest additionalParameters]];
[request setBirthday:[customEventRequest userBirthday]];
[request setGender:[customEventRequest userGender]];
[request setTesting:[customEventRequest isTesting]];
if ([customEventRequest userHasLocation]){
[request setLocationWithLatitude:[customEventRequest userLatitude]
longitude:[customEventRequest userLongitude]
accuracy:[customEventRequest userLocationAccuracyInMeters]];
}
[self.interstitial loadRequest:request];
}
- (void)presentFromRootViewController:(UIViewController *)rootViewController {
[self.interstitial presentFromRootViewController:rootViewController];
}
插頁式廣告自定義事件接口要求您實現presentFromRootViewController:方法。當您告知移動廣告SDK 展現插頁式廣告時,中介層會調用此方法。
七:通知 KeyMob中介
與橫幅廣告自定義事件示例同樣,您須要爲廣告網絡實現廣告監聽器以將消息轉發回中介。如下示例介紹了 KeyMob的GADInterstitialDelegate的實現方法。
#pragma mark GADInterstitial Callbacks
- (void)interstitialDidReceiveAd:(GADInterstitial *)view {
[self.delegate customEventInterstitial:self didReceiveAd:view];
}
- (void) interstitial:(GADInterstitial *)ad
didFailToReceiveAdWithError:(GADRequestError *)error {
[self.delegate customEventInterstitial:self didFailAd:error];
}
- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
[self.delegate customEventInterstitialWillPresent:self];
}
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
[self.delegate customEventInterstitialWillDismiss:self];
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
[self.delegate customEventInterstitialDidDismiss:self];
}
- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
[self.delegate customEventInterstitialWillLeaveApplication:self];
}
@end
將消息發回中介層可以讓其繼續中介廣告瀑布流。插頁式廣告沒有點擊次數,所以不會有插頁式廣告點擊事件傳遞迴中介層。
這裏有一些應用能添加廣告教程,如android 應用、IOS應用、 flash air應用、 cordova5應用 ,詳細教程網站http://www.keymob.com這是一個專業應用廣告管理工具——KeyMob支持插頁式廣告、橫幅廣告、Banner、視頻廣告等衆多流行廣告平臺。打開教程你將會學習到更多,但願能幫到忙!
android