Google AdMobs custom click events not working with unsupported network

Google AdMobs custom click events not working with unsupported network



I am using Google AdMobs DFP to serve up mediation banners from other networks. I have added Millennial and InMobi fine but now I need to add a network (YOC group) that does not have an adapter for DFP so I need to implement 'custom event banners'. I have read the guides and technical documents on implementing unsupported mediator networks with custom events but still cannot understand how it hooks up the two SDKs (Google AdMobs SDK and the mediator network's SDK).



The network that doesn't have an adapter (YOC) works if I hard-code the yoc ad id (of the format '9A9A9AA99999999A999AA9A99AA99AAAA999A9AA') to a sample ad and send off the request. The banner comes back fine and uses the YOC SDK to show an interactive/rich media advert.



However in my app I only have a Google DFP account id (of the format '/9999/company.app/channel') which I send off a request for using Google AdMobs SDK to DFP. The request then returns a response with the specific mediator ad network to try and request a banner advert from. My current setup is that YOC serves 100% of ads in DFP.



Problem: I get a banner advert returned from the YOC ad network and it displays on screen. It registers page impressions (with DFP) but there is no response to a touch/press event the way it works as if I hard-code the initialisation parameters of the yoc ad view. I can't however hard-code the yoc ad id (when initialising) because it would only work for one banner advert and I need different banners for each specific advert in each channel.



Below is the sample code I am trying to implement using just NSLogs in the methods to log to the console and show that the methods are being called. It is a very basic app and puts all the code in one place for ease of reading.



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/channel_specific_id";

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/channel_specific_id)'

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/channel_specific_id'
[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



Please can someone help give me things to try out and find out how to get the advert banner view returned from Google DFP responding to click events!?




1 Answer
1



There is a guide here on how to develop custom events.



If you're using AdMob SDK Mediation with ad unit /9999/company.app/channel, then this ad unit should be an SDK Mediation creative within DFP. One of your networks should be a Custom Event with the following settings:


/9999/company.app/channel


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)



Then when implementing the custom event, you can reference serverParameter as the YOCTag like you already have.


serverParameter



You don't want to implement GADCustomEventBannerDelegate yourself. By your class implementing GADCustomEventBanner, and adding:


GADCustomEventBannerDelegate


GADCustomEventBanner


@synthesize delegate



at the top of your implementation, you have access to an instance of this object via:


self.delegate



You'll want to use that delegate to tell the custom event (and thereby AdMob Mediation) that YOC returned or failed to return an ad. Based on the YOC delegate, your mapping might look something like this:


- (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];



Finally, you don't want to invoke GADCustomEventBannerDelegate methods in your GADBannerViewDelegate callback methods. These are invoked by AdMob telling you that mediation came back with an ad. The GADBannerViewDelegate implementation is part of your main app, and should stay out of your custom event class's implementation.


GADCustomEventBannerDelegate


GADBannerViewDelegate


GADBannerViewDelegate



I know the guide invokes the custom event delegate methods in its GADBannerViewDelegate implementation. The difference is the guide is writing a custom event to implement AdMob, so in the context of the guide, the GADBannerViewDelegate is behaving like the YOCAdViewDelegate in your example.


GADBannerViewDelegate


GADBannerViewDelegate


YOCAdViewDelegate






Eric, we've finally cracked it! Thank you so much for all your help.

– Henry Heleine
Apr 20 '13 at 14:47



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ