Skip to content

Listening for Ad Events

awallace87 edited this page Aug 23, 2016 · 1 revision

Listening for Ad Events

For each Placement View a publisher has the option to attach a listener to the page view in order to be notified of major events associated with the ad request.

Here is how you can add a listener to a Placement View:

YMPlacementView.Builder builder = new YMPlacementView.Builder(context);
            builder.placementId(YMConstants.hyperscrollerPlacementId);

            //Attach anonymous YMPlacementListener to Placement View
            builder.listener(new YMPlacementListener {
              @Override
                public void adDisplayFailed(YMException exception) {

                }

                @Override
                public void adDisplayed() {

                }

                @Override
                public void adLeavesApplication() {

                }

                @Override
                public void adClicked() {

                }
            });

            view = builder.build();

You can also use your own custom implementation of the YMPlacementListener interface, which is as follows:

public interface YMPlacementListener {
    void adDisplayFailed(YMException exception);
    void adDisplayed();
    void adLeavesApplication();
    void adClicked();
}

Listener Callback Description

  • adDisplayed(): called when an ad is successfully loaded and added to the YMPlacementView
  • adDisplayFailed(YMException exception): called when an ad request/display fails. The exception contains a message detailing the failure reason.
  • adLeavesApplication(): called when an action from the advertisement leads to the user being directed from the application.
  • onAdClicked(): called when a user clicks on an advertisement.

Android-SDK-Beta

  • Home
  • [Key Terms](Key Terms)

Start Here


  • [Listening for Ad Events](Listening for Ad Events)
  • Additional Settings
  • [Page View](Page View)
  • [Custom Content Frame](Content Frame)
  • Proguard

Have a previous SDK?

  • [Upgrade Guide](Upgrade Guide)

Clone this wiki locally