Search code examples
javaandroidkotlinads

Google ad click is not opening the external web browser


I am trying to implement the ad in my app with Custom Native Ad Format - https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/custom-formats#java_1

So, according to the documentation I am going with the approach described there and creating the ad

...
private void setListeners() {
...
    imageView.setOnClickListener(v -> {
        nativeCustomFormatAd.performClick("IMAGE");
    });
...
}

private NativeCustomFormatAd nativeCustomFormatAd;

AdLoader adLoader = new AdLoader.Builder(context, "/6499/example/native")
    .forCustomFormatAd("10063170",
      new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
          @Override
          public void onCustomFormatAdLoaded(NativeCustomFormatAd ad) {
              // Show the custom format and record an impression.

             nativeCustomFormatAd = ad;
              Drawable drawable = vm.nativeCustomFormatAd.getImage("IMAGE").getDrawable();
              imageView.setDrawable(drawable);
          }
      },
      new NativeCustomFormatAd.OnCustomClickListener() {
          @Override
          public void onCustomClick(NativeCustomFormatAd ad, String s) {
              // Handle the click action
          }
      })
    .withAdListener( ... )
    .withNativeAdOptions( ... )
    .build();


            @SuppressLint("VisibleForTests")
            AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
            adLoader.loadAd(adManagerAdRequest);
...

So, it looks pretty simple I try to make a request for the ad then I got (in a callback) NativeCustomFormatAd, save it as a class member, and along with it get drawable and set it to the imageView (to present it in the UI). Once a user clicks on the imageView I get an event in the click listener and invoke nativeCustomFormatAd.performClick("IMAGE");.

The problem is that I expect that once I transfer the ad click to the SDK (by nativeCustomFormatAd.performClick("IMAGE");) SDK is supposed to open the external browser, but instead nothing happens.

P.S. I am sure that nativeCustomFormatAd.performClick("IMAGE"); getting invoked and also I see that SDK gets the click as I got a callback event here:

...
      new NativeCustomFormatAd.OnCustomClickListener() {
          @Override
          public void onCustomClick(NativeCustomFormatAd ad, String s) {
              // Handle the click action
          }
      })
...

What am I missing here?


Solution

  • According to the docs you linked:

    When a click is performed on a custom format ad, there are three possible responses from the SDK, attempted in this order:

    1. Invoke the OnCustomClickListener from AdLoader, if one was provided.
    2. For each of the ad's deep link URLs, attempt to locate a content resolver and start the first one that resolves.
    3. Open a browser and navigate to the ad's traditional Destination URL.

    Also:

    If you pass a listener object in, the SDK instead invokes its onCustomClick method and takes no further action.

    Therefore, it seems you have to pass a null OnCustomClickListener.