Simpler testing with new AdMob test ads


Kotlin and the Google Mobile Ads SDK


Mobile Ads Garage #3: Banner ad best practices


The Mobile Ads Garage: A new video series about using the Google Mobile Ads SDK


Adding SDK-less mediation to your project


Announcing the Google Mobile Ads API Demo apps


Announcing two new versions of the Google Mobile Ads SDK, plus the Native Ads beta!


From a DFP Line Item to Mobile Ads SDK Code


Announcing v7.0 of the Google Mobile Ads SDK for Android


Rollback of roadblocks feature in the Mobile Ads SDK


Announcing version 7.0.0 of the Google Mobile Ads SDK for iOS


New Google Mobile Ads SDK Adds Support for DFP, Search Ads, and Ad Exchange


Using DFP App Events with the Google AdMob SDK
The next step is to have the application code listen for these app events. Here are the iOS and Android versions of this method, respectively:
// iOS - (void)adView:(DFPBannerView *)banner didReceiveAppEvent:(NSString *)name withInfo:(NSString *)info { NSLog(@"Received app event (%@, %@)", name, info); // Checking for a "color" event name with information being a color. if ([name isEqualToString:@"color"]) { if ([info isEqualToString:@"red"]) { self.view.backgroundColor = [UIColor redColor]; } else if ([info isEqualToString:@"green"]) { self.view.backgroundColor = [UIColor greenColor]; } } } // Android @Override public void onAppEvent(Ad ad, String name, String info) { String message = String.format("Received app event (%s, %s)", name, info); Log.d(LOG_TAG, message); if ("color".equals(name)) { LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout); if ("red".equals(info)) { layout.setBackgroundColor(Color.RED); } else if ("green".equals(info)) { layout.setBackgroundColor(Color.GREEN); } } }
Remember to register this callback on the banner view:
// iOS [bannerView_ setAppEventDelegate:self]; // Android adView.setAppEventListener(this);
That’s it! If you load this ad into your banner view, your application will change its background color to red when the ad is loaded, and green when the ad is clicked. This example can be extended to change the implementation of the app event listener or to fire app events at any point during the creative’s lifecycle.
Let us know on the forum if you have any questions about app events specifically or the Google AdMob SDK in general. You can also follow us on our plus page for AdMob-related updates.
Edit: Fixed plus page link.
- Eric Leichtenschlag, AdMob Team


Announcing v201208 of the DFP API

