AppEvent callback is not working as expected for Banner ads

50 views
Skip to first unread message

vishal chougule

unread,
Oct 15, 2024, 6:37:40 AM10/15/24
to Google Mobile Ads SDK Developers
Hi Team, 

I have integrated GAM Ads SDK v23.0.0 for banner ads and admob.events.dispatchAppEvent("color", "blue", true); .js API to get onAppEvent(String name, String info) callback on the client side.
To do the same I have used the below documents
Now, I want the appEvent() delegation before onAdLoaded() callback as the API doc saysopt_sendBeforePageLoad parameter can be used to get onAppEvent before ad received event.
Below is the reference API for the same.
admob.events.dispatchAppEvent(name, opt_info, opt_sendBeforePageLoad)
Notify the application with an app event with optional information.
Arguments:
name : 
An identifier for the app event.

opt_info : 
(string | undefined)
The information to be sent to the app.

opt_sendBeforePageLoad : 
(boolean | undefined)
Set to true when the app event is desired before the SDK notifies the publisher delegate of a 'received ad' event.

Can you please help me get the appEvent() before onAdLoaded() callback on GAM SDKs banner ads?

Thanks,
Vishal

Mobile Ads SDK Forum Advisor

unread,
Oct 16, 2024, 8:21:42 AM10/16/24
to chougul...@gmail.com, google-adm...@googlegroups.com

Hi Vishal,

Thank you for contacting the Mobile Ads SDK support team.

Yes, you can get the appEvent() before onAdLoaded() callback on GAM SDKs banner ads. You can listen for Ad Manager specific app events using AppEventListener. These events can occur at any time during the ad's lifecycle, even before onAdLoaded() is called. void onAppEvent(String name, String info) is called when an app event occurs in an ad. This interface can be implemented by your activity or any other object:
 

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
 super.onViewCreated(view, savedInstanceState)
 fragmentBinding.appeventsAvMain.appEventListener = AppEventListener { name, data ->
   // The Ad Manager ad that this fragment loads contains JavaScript code that sends App
   // Events to the host application. This AppEventListener receives those events,
   // and sets the background of the fragment to match the data that comes in.
   // The ad will send "red" when it loads, "blue" five seconds later, and "green"
   // if the user taps the ad.
   // This is just a demonstration, of course. Your apps can do much more interesting
   // things with App Events.
   if (name == "color") {
     val color =
       when (data) {
         "blue" -> Color.rgb(0xD0, 0xD0, 0xFF)
         "red" -> Color.rgb(0xFF, 0xD0, 0xD0)
         else -> Color.rgb(0xD0, 0xFF, 0xD0) // Green.
       }
     fragmentBinding.root.setBackgroundColor(color)
   }
 }
 val adRequest = AdManagerAdRequest.Builder().build()
 fragmentBinding.appeventsAvMain.loadAd(adRequest)
}

Remember to set the delegate using the appEventDelegate property before making the request for an ad.  I cannot comment on the API part because we can only assist with technical queries/concerns related to the Google Mobile Ads SDK. Also, refer to the Android API Demo app for an example of the implementation of app events.

This message is in relation to case "ref:!00D1U01174p.!5004Q02vGeWn:ref" (ADR-00271783)

Thanks,
 
Google Logo Mobile Ads SDK Team


Reply all
Reply to author
Forward
0 new messages