Control user click events

This guide explains how to implement more control over clickthrough in your IMA SDK implementation. "Clickthrough" refers to the process of a user clicking on an ad and getting to the landing page for that ad. The examples in this guide demonstrates how to configure where that landing page opens and how to listen for events related to users visiting that page.

Prerequisites

An iOS application with the IMA SDK implemented.

Configuring clickthrough

The IMA SDK offers two options for opening ad landing pages—via an in-app browser, or via Safari. By default, the SDK opens pages using Safari. To update the SDK to use an in-app browser, you need to use IMAAdsRenderingSettings :

Swift

 func 
  
 createAdsRenderingSettings 
 () 
  
 { 
  
 self 
 . 
 adsRenderingSettings 
  
 = 
  
 IMAAdsRenderingSettings 
 (); 
  
 self 
 . 
 adsRenderingSettings 
 . 
 linkOpenerDelegate 
  
 = 
  
 self 
 ; 
  
 self 
 . 
 adsRenderingSettings 
 . 
 linkOpenerPresentingController 
  
 = 
  
 self 
 ; 
 } 

Objective-C

 - 
 ( 
 void 
 ) 
 createAdsRenderingSettings 
  
 { 
  
 self 
 . 
 adsRenderingSettings 
  
 = 
  
 [[ 
 IMAAdsRenderingSettings 
  
 alloc 
 ] 
  
 init 
 ]; 
  
 self 
 . 
 adsRenderingSettings 
 . 
 linkOpenerDelegate 
  
 = 
  
 self 
 ; 
  
 self 
 . 
 adsRenderingSettings 
 . 
 linkOpenerPresentingController 
  
 = 
  
 self 
 ; 
 } 
Once you've configured the IMAAdsRenderingSettings instance, you can pass it to the IMAAdsManager initialization method:

Swift

 self 
 . 
 adsManager 
 . 
 initialize 
 ( 
 withAdsRenderingSettings 
 : 
  
 adsRenderingSettings 
 ); 

Objective-C

 [ 
 self 
 . 
 adsManager 
  
 initializeWithAdsRenderingSettings 
 : 
 adsRenderingSettings 
 ]; 
The IMA SDK provides the IMALinkOpenerDelegate to communicate when the user is about to see or has just closed a clickthrough page. To use this delegate, add it to your delegate list in the header, and implement its methods. In the header:

Swift

 class 
  
 ViewController 
 : 
  
 UIViewController 
 , 
  
 IMALinkOpenerDelegate 
  
 { 

Objective-C

 @interface 
 ViewController 
: UIViewController<IMALinkOpenerDelegate> 
And in the implementation:

Swift

 func 
  
 linkOpenerWillOpen 
 ( 
 externalBrowser 
 : 
  
 NSObject 
 ) 
  
 { 
  
 print 
 ( 
 "External browser will open." 
 ) 
 } 
 func 
  
 linkOpenerWillOpen 
 ( 
 inAppLink 
 : 
  
 NSObject 
 ) 
  
 { 
  
 print 
 ( 
 "In-app browser will open." 
 ) 
 } 
 func 
  
 linkOpenerDidOpen 
 ( 
 inAppLink 
 : 
  
 NSObject 
 ) 
  
 { 
  
 print 
 ( 
 "In-app browser did open." 
 ) 
 } 
 func 
  
 linkOpenerWillClose 
 ( 
 inAppLink 
 : 
  
 NSObject 
 ) 
  
 { 
  
 print 
 ( 
 "In-app browser will close." 
 ) 
 } 
 func 
  
 linkOpenerDidClose 
 ( 
 inAppLink 
 : 
  
 NSObject 
 ) 
  
 { 
  
 print 
 ( 
 "In-app browser did close." 
 ) 
 } 

Objective-C

 - 
 ( 
 void 
 ) 
 linkOpenerWillOpenExternalBrowser: 
 ( 
 NSObject 
  
 * 
 ) 
 linkOpener 
  
 { 
  
 NSLog 
 ( 
 @"External browser will open." 
 ); 
 } 
 - 
 ( 
 void 
 ) 
 linkOpenerWillOpenInAppBrowser: 
 ( 
 NSObject 
  
 * 
 ) 
 linkOpener 
  
 { 
  
 NSLog 
 ( 
 @"In-app browser will open." 
 ); 
 } 
 - 
 ( 
 void 
 ) 
 linkOpenerDidOpenInAppBrowser: 
 ( 
 NSObject 
  
 * 
 ) 
 linkOpener 
  
 { 
  
 NSLog 
 ( 
 @"In-app browser did open." 
 ); 
 } 
 - 
 ( 
 void 
 ) 
 linkOpenerWillCloseInAppBrowser: 
 ( 
 NSObject 
  
 * 
 ) 
 linkOpener 
  
 { 
  
 NSLog 
 ( 
 @"In-app browser will close." 
 ); 
 } 
 - 
 ( 
 void 
 ) 
 linkOpenerDidCloseInAppBrowser: 
 ( 
 NSObject 
  
 * 
 ) 
 linkOpener 
  
 { 
  
 NSLog 
 ( 
 @"In-app browser did close." 
 ); 
 } 
Create a Mobile Website
View Site in Mobile | Classic
Share by: