Respond to clicks on ads

When a user clicks on an ad or a related button, your application is responsible for responding. The PSDK provides you with information about the destination URL for the click.

  1. Set up an event listener for the PSDK to provide you with click-through information.
    1. Register an AdPlaybackEventListener.onAdClick.
    When an end user clicks a banner, the PSDK dispatches this notification, including information about the destination for the click.
  2. Monitor user interactions on clickable ads.
  3. When the user touches or clicks the ad or button, notify the PSDK.
    1. To do this, call notifyClick on the MediaPlayerView.
  4. Listen for the onAdClick(AdBreak adBreak, Ad ad, AdClick adClick) event from the PSDK.
  5. Retrieve the click-through URL and related information.
    1. Use the getter methods for the AdClick instance.
  6. Pause the video.
  7. Use the click-through information to display the ad click-through URL and any related information. For example, you could display it in one of the following ways:
    • Open the click-through URL in a browser within your application.

      On desktop platforms, the video ad playback area is typically used for invoking click-through URLs upon user clicks.

    • Redirect the user to their external mobile web browser.

      On mobile devices, the video ad playback area is used for other functions, such as hiding and showing controls, pausing playback, expanding to full screen, and so on. Therefore, on mobile devices, a separate view, such as a sponsor button, is usually presented to the user as a means to launch the click-through URL.

  8. Close the browser window in which the click-through information is displayed and resume playing the video.
For example:
private final MediaPlayer.AdPlaybackEventListener _adPlaybackEventListener = 
 new MediaPlayer.AdPlaybackEventListener() {
   ...    
}
@Override
public void onAdStart(AdBreak adBreak, Ad ad) {
   //TODO: Implement external tracking logic        
   //TODO: Notify the user that an ad has started by an UI update    
   // Notify the user that the ad is clickable
   if (ad.isClickable()) {
       //TODO: Modify the UI to give the user the possibility to 
               choose to click upon the primary asset
   }
}
@Override
public void onAdClick(AdBreak adBreak, Ad ad, AdClick adClick) {
   // Open the native browser to display the click through url
   Uri uri = Uri.parse(adClick.getUrl());    
   Intent intent = new Intent(ACTION_VIEW, uri);
   try {
       startActivity(intent);
   } catch (Exception e) {
       // Log exception
   }
}