2013-04-16 60 views
1

我正在使用Google AdMobs DFP來提供來自其他網絡的中介橫幅。我添加了Millennial和InMobi,但現在我需要添加一個沒有DFP適配器的網絡(YOC組),因此我需要實施「自定義事件」。我已閱讀有關使用自定義事件實施不受支持的中介網絡的指南和技術文檔,但仍無法理解它是如何連接兩個SDK(Google AdMobs SDK和中介網絡的SDK)的。Google AdMobs自定義點擊事件不適用於不受支持的網絡

如果我將yoc ad id(格式爲'9A9A9AA99999999A999AA9A99AA99AAAA999A9AA')硬編碼爲示例廣告併發送請求,那麼沒有適配器(YOC)的網絡可以正常工作。橫幅迴歸正常,並使用YOC SDK顯示交互式/富媒體廣告。

但是在我的應用程序中,我只有一個Google DFP帳戶ID(格式爲「/9999/company.app/channel」),我發送了使用Google AdMobs SDK(v。6.2.1)的請求以DFP。該請求然後返回具有特定中介廣告網絡的響應以嘗試並從中請求橫幅廣告。我目前的設置是YOC在DFP中投放100%的廣告。

問題:我得到從YOC廣告網絡返回的橫幅廣告,並在屏幕上顯示。它會註冊頁面展示次數(使用DFP廣告管理系統),但它不會像觸摸/按下事件那樣對我的廣告視圖的初始化參數進行硬編碼。然而,我不能對yoc廣告ID進行硬編碼(初始化時),因爲它只適用於一個橫幅廣告,並且我需要針對每個頻道中的每個特定廣告使用不同的橫幅廣告。

下面是我試圖在方法中使用NSLogs來實現登錄到控制檯並顯示正在調用方法的示例代碼。這是一個非常基本的應用程序,並將所有代碼放在一個地方以便於閱讀。

AppDelegate.h

#import < UIKit/UIKit.h> 
#import "GADBannerView.h" 
#import "GADBannerViewDelegate.h" 
#import "GADCustomEventBanner.h" 
#import "GADCustomEventBannerDelegate.h" 
#import < YOCAdSDK/YOCAdView.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate, GADBannerViewDelegate, GADCustomEventBanner, GADCustomEventBannerDelegate, YOCAdViewDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) UIViewController *root; 

@end 

AppDelegate.m

#import "AppDelegate.h" 
#import "GADBannerView.h" 
#import <YOCAdSDK/YOCAdSize.h> 

@implementation AppDelegate 

@synthesize root; 
@synthesize delegate; // GADCustomEventBannerDelegate set on GADCustomEventBanner 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    CGRect bounds = [[UIScreen mainScreen] bounds]; 
    self.window = [[UIWindow alloc] initWithFrame:bounds]; 
    self.window.backgroundColor = [UIColor greenColor]; 

    GADBannerView *banner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeLeaderboard origin:CGPointMake(0, 0)]; 
    self.root = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 
    UIView *base = [[UIView alloc] initWithFrame:bounds]; 
    base.backgroundColor = [UIColor greenColor]; 
    self.root.view = base; 

    // the adUnitID is always of our DFP account number of the format '/9999/company.app/aa_aa<channelName>_<channelName>app' 
    banner.adUnitID = @"/9999/company.app/aa_aadebate_debateapp"; 

    banner.delegate = self; 
    banner.rootViewController = self.root; 

    self.delegate = self; 

    [base addSubview:banner]; 
    [base bringSubviewToFront:banner]; 
    [banner loadRequest:[GADRequest request]]; 

    [self.window setRootViewController:self.root]; 

    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 


#pragma mark GADBannerViewDelegate 

- (void)adViewDidReceiveAd:(GADBannerView *)view { 
    NSLog(@" adViewDidReceiveAd "); 
    NSLog(@" view: %@ ", [view description]); 

    // for other ad networks here we get view.mediatedAdView = IMAdView (InMobi) or view.mediatedAdView = MMAdView (Millennial) but with YOC view.mediatedAdView = nil; 

    [self.delegate customEventBanner:self didReceiveAd:view]; 
} 

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error { 
    NSLog(@" didFailToReceiveAdWithError "); 
    [self.delegate customEventBanner:self didFailAd:error]; 
} 

- (void)adViewWillPresentScreen:(GADBannerView *)adView { 
    NSLog(@" adViewWillPresentScreen "); 
    [self.delegate customEventBanner:self clickDidOccurInAd:adView]; 
    [self.delegate customEventBannerWillPresentModal:self]; 
} 

- (void)adViewWillDismissScreen:(GADBannerView *)adView { 
    NSLog(@" adViewWillDismissScreen "); 
    [self.delegate customEventBannerWillDismissModal:self]; 
} 

- (void)adViewDidDismissScreen:(GADBannerView *)adView { 
    NSLog(@" adViewDidDismissScreen "); 
    [self.delegate customEventBannerDidDismissModal:self]; 
} 

- (void)adViewWillLeaveApplication:(GADBannerView *)adView { 
    NSLog(@" adViewWillLeaveApplication "); 
    [self.delegate customEventBannerWillLeaveApplication:self]; 
} 


#pragma mark GADCustomEventBanner 

- (void)requestBannerAd:(GADAdSize)adSize 
       parameter:(NSString *)serverParameter 
        label:(NSString *)serverLabel 
       request:(GADCustomEventRequest *)request { 
    NSLog(@" requestBannerAd "); 

    // not sure if we initialiase the YOC tag here or how we would do this if can't hard code the yocTag to the format '9A9A9AA99999999A999AA9A99AA99AAAA999A9AA' 
    // and we only have the banner view returned from DFP with the id '/9999/company.app/aa_aadebate_debateapp' 

    YOCAdView *yocAdView = [[YOCAdView alloc] initWithYOCTag:serverParameter delegate:self size:kLeaderboard728x90 position:CGPointMake(0, 0)]; 
    yocAdView.delegate = self; 
    [yocAdView load]; 

    [self.root.view addSubview:yocAdView]; 
} 


#pragma mark GADCustomEventBannerDelegate 

- (void)customEventBanner:(id<GADCustomEventBanner>)customEvent didReceiveAd:(UIView *)view { 
    NSLog(@" [(GADBannerView *)view adUnitID]: %@ ", [(GADBannerView *)view adUnitID]); 
    NSLog(@" [(GADBannerView *)view delegate]: %@ ", [(GADBannerView *)view delegate]); 
    NSLog(@" [(id<YOCAdViewDelegate>)[customEvent delegate] viewControllerForPresentingYOCAdView]: %@ ", [(id<YOCAdViewDelegate>)[customEvent delegate] viewControllerForPresentingYOCAdView]); 

    // not sure if we initialiase the YOC tag here or how we would do this if can't hard code the yocTag to '9A9A9AA99999999A999AA9A99AA99AAAA999A9AA" 
    // and we only have the banner view returned from DFP with the id '/9999/company.app/aa_aadebate_debateapp' 
    [customEvent requestBannerAd:kGADAdSizeLeaderboard parameter:@"???" label:nil request:nil]; 

    // the key might be that the [customEvent delegate] is of type YOCAdViewDelegate and we can do code specific to YOC here... 
    // but again not sure how to initialize the YOCAdView because we already have the banner view returned from DFP (with a different format account id) 
    // [(id<YOCAdViewDelegate>)[customEvent delegate] yocAdViewDidInitialize:yocAdView]; 
} 

- (void)customEventBanner:(id<GADCustomEventBanner>)customEvent didFailAd:(NSError *)error { 
    NSLog(@" customEventBanner:didFailAd "); 
} 

- (void)customEventBanner:(id<GADCustomEventBanner>)customEvent clickDidOccurInAd:(UIView *)view { 
    NSLog(@" customEventBanner:clickDidOccurInAd "); 
} 

- (void)customEventBannerWillPresentModal:(id<GADCustomEventBanner>)customEvent { 
    NSLog(@" customEventBannerWillPresentModal "); 
} 

- (void)customEventBannerWillDismissModal:(id<GADCustomEventBanner>)customEvent { 
    NSLog(@" customEventBannerWillDismissModal "); 
} 

- (void)customEventBannerDidDismissModal:(id<GADCustomEventBanner>)customEvent { 
    NSLog(@" customEventBannerDidDismissModal "); 
} 

- (void)customEventBannerWillLeaveApplication:(id<GADCustomEventBanner>)customEvent { 
    NSLog(@" customEventBannerWillLeaveApplication "); 
} 


#pragma mark YOCAdViewDelegate 

- (UIViewController *)viewControllerForPresentingYOCAdView { 
    NSLog(@" viewControllerForPresentingYOCAdView "); 
    return self.root; 
} 

- (void)yocAdViewDidInitialize:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewDidInitialize "); 
} 

- (void)yocAdView:(YOCAdView *)yocAdView didFailWithError:(NSError *)error { 
    NSLog(@" didFailWithError: %@ ", error); 
} 

- (void)yocAdViewDidHide:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewDidHide "); 
} 

- (void)yocAdViewDidReload:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewDidReload "); 
} 

- (void)yocAdViewWillPresentModalViewController:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewWillPresentModalViewController "); 
} 

- (void)yocAdViewWillDismissModalViewController:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewWillDismissModalViewController "); 
} 


@end 

請誰能幫給我的東西來嘗試,並找出如何讓廣告橫幅視圖從谷歌DFP響應返回點擊事件!?

回答

1

有關如何開發自定義事件的指南here

如果您將AdMob SDK中介與廣告單元/9999/company.app/channel一起使用,則該廣告單元在DFP中應爲SDK Mediation creative。您的一個網絡應該是一個Custom Event以下設置:

Parameter: 9A9A9AA99999999A999AA9A99AA99AAAA999A9AA (or whatever your YOC tag is) 
Label: YOC Group (This is just a label so you remember what this custom event is for) 
Class Name: AppDelegate (You should really implement the custom event in it's own 
         class, and replace the class name with that class) 

然後實現自定義事件時,可以參考serverParameter作爲YOCTag像你已經有了。

你不想自己實現GADCustomEventBannerDelegate。通過你的類實現GADCustomEventBanner,並補充說:

@synthesize delegate 

在你的實現上,你必須通過訪問該對象的一個​​實例:

self.delegate 

你要使用該委託告訴自定義事件(從而AdMob中介)YOC返回或未能返回廣告。基於該YOC代表,你的映射可能是這個樣子:

- (UIViewController *)viewControllerForPresentingYOCAdView { 
    NSLog(@" viewControllerForPresentingYOCAdView "); 
    return self.root; 
} 

- (void)yocAdViewDidInitialize:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewDidInitialize "); 
    // Assuming this means the yocAdView was received. 
    [self.delegate customEventBanner:self didReceiveAd:yocAdView]; 
} 

- (void)yocAdView:(YOCAdView *)yocAdView didFailWithError:(NSError *)error { 
    NSLog(@" didFailWithError: %@ ", error); 
    [self.delegate customEventBanner:self didFailAd:error]; 
} 

- (void)yocAdViewDidHide:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewDidHide "); 
} 

- (void)yocAdViewDidReload:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewDidReload "); 
    [self.delegate customEventBanner:self didReceiveAd:yocAdView]; 
} 

- (void)yocAdViewWillPresentModalViewController:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewWillPresentModalViewController "); 
    [self.delegate customEventBanner:self clickDidOccurInAd:yocAdView]; 
    [self.delegate customEventBannerWillPresentModal:self]; 
    [self.delegate customEventBannerWillLeaveApplication:self]; 
} 

- (void)yocAdViewWillDismissModalViewController:(YOCAdView *)yocAdView { 
    NSLog(@" yocAdViewWillDismissModalViewController "); 
    [self.delegate customEventBannerWillDismissModal:self]; 
} 

最後,你不想來調用你的GADBannerViewDelegate回調方法GADCustomEventBannerDelegate方法。 AdMob會通過調用這些信息告訴您調解是否返回了廣告。 GADBannerViewDelegate實現是您的主應用程序的一部分,應該遠離您的自定義事件類的實現。

我知道該指南調用了其GADBannerViewDelegate實現中的自定義事件委託方法。區別在於該指南正在撰寫自定義事件以實施AdMob,因此在本指南的上下文中,GADBannerViewDelegate的行爲與您示例中的YOCAdViewDelegate相似。

+0

埃裏克,我們終於破解了!非常感謝您的幫助。 –

相關問題