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. Add an observer for PTMediaPlayerAdClickNotification.
    This enables your application to receive PSDK events that provide information about the destination URL for a click on an ad.
  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, use [_player notifyClick:_currentAd.primaryAsset];.
  4. Listen for the PTMediaPlayerAdClickNotification event from the PSDK.
  5. Retrieve the click-through URL and related information.
    1. Use the PTMediaPlayerAdClickURLKey object.
  6. Pause the video.
  7. 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:
// Listening for click notification 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMediaPlayerAdClick:) 
 name:PTMediaPlayerAdClickNotification object:self.player];
- (void) onMediaPlayerAdClick:(NSNotification *) notification {
   NSString *url = [notification.userInfo objectForKey:PTMediaPlayerAdClickURLKey]; 
   if (url != nil) {
       [self openBrowser:[NSURL URLWithString:url]];
   }
}