Contrôler les événements de clic des utilisateurs
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Ce guide explique comment mieux contrôler les clics dans votre implémentation du SDK IMA. Le terme "clics" désigne le processus par lequel un utilisateur clique sur une annonce et accède à la page de destination de cette annonce. Les exemples de ce guide montrent comment configurer l'emplacement d'ouverture de cette page de destination et comment écouter les événements liés aux utilisateurs qui accèdent à cette page.
Prérequis
Une application iOS avec le SDK IMA implémenté.
Configurer le clic
Modifier l'outil d'ouverture du lien
Le SDK IMA propose deux options pour ouvrir les pages de destination des annonces : via un navigateur intégré à l'application ou via Safari. Par défaut, le SDK ouvre les pages à l'aide de Safari. Pour mettre à jour le SDK afin d'utiliser un navigateur intégré à l'application, vous devez utiliser
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;
}
Une fois que vous avez configuré l'instance
IMAAdsRenderingSettings
, vous pouvez la transmettre à la méthode d'initialisation
IMAAdsManager
:
Swift
self.adsManager.initialize(withAdsRenderingSettings: adsRenderingSettings);
Objective-C
[self.adsManager initializeWithAdsRenderingSettings:adsRenderingSettings];
Le SDK IMA fournit
IMALinkOpenerDelegate
pour communiquer lorsque l'utilisateur est sur le point de voir ou vient de fermer une page de clic. Pour utiliser ce délégué, ajoutez-le à votre liste de délégués dans l'en-tête et implémentez ses méthodes. Dans l'en-tête :
Swift
class ViewController: UIViewController, IMALinkOpenerDelegate {
Objective-C
@interface ViewController : UIViewController<IMALinkOpenerDelegate>
Et dans l'implémentation:
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.");
}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (UTC)."],[[["\u003cp\u003eThis guide explains how to control the clickthrough process in your iOS app using the IMA SDK, allowing you to decide where ad landing pages open (in-app or Safari).\u003c/p\u003e\n"],["\u003cp\u003eYou can configure the SDK to use an in-app browser instead of the default Safari by implementing \u003ccode\u003eIMAAdsRenderingSettings\u003c/code\u003e and passing it to the \u003ccode\u003eIMAAdsManager\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eIMALinkOpenerDelegate\u003c/code\u003e enables you to monitor clickthrough events, such as when the ad landing page opens or closes, providing insights into user interaction with ads.\u003c/p\u003e\n"]]],[],null,["This guide explains how to implement more control over clickthrough in your IMA SDK\nimplementation. \"Clickthrough\" refers to the process of a user clicking on an ad and getting to\nthe landing page for that ad. The examples in this guide demonstrates how to configure where that\nlanding page opens and how to listen for events related to users visiting that page.\n\nPrerequisites\n\n\nAn iOS application with the IMA SDK implemented.\n\nConfiguring clickthrough\n\nChanging the link opener 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`: \n\nSwift \n\n```swift\nfunc createAdsRenderingSettings() {\n self.adsRenderingSettings = IMAAdsRenderingSettings();\n self.adsRenderingSettings.linkOpenerDelegate = self;\n self.adsRenderingSettings.linkOpenerPresentingController = self;\n}\n```\n\nObjective-C \n\n```objective-c\n- (void)createAdsRenderingSettings {\n self.adsRenderingSettings = [[IMAAdsRenderingSettings alloc] init];\n self.adsRenderingSettings.linkOpenerDelegate = self;\n self.adsRenderingSettings.linkOpenerPresentingController = self;\n}\n```\nOnce you've configured the `IMAAdsRenderingSettings` instance, you can pass it to the `IMAAdsManager` initialization method: \n\nSwift \n\n```swift\nself.adsManager.initialize(withAdsRenderingSettings: adsRenderingSettings);\n```\n\nObjective-C \n\n```objective-c\n[self.adsManager initializeWithAdsRenderingSettings:adsRenderingSettings];\n```\n\nListening for clickthrough-related events 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: \n\nSwift \n\n```swift\nclass ViewController: UIViewController, IMALinkOpenerDelegate {\n```\n\nObjective-C \n\n```objective-c\n@interface ViewController : UIViewController\u003cIMALinkOpenerDelegate\u003e\n```\nAnd in the implementation: \n\nSwift \n\n```swift\nfunc linkOpenerWillOpen(externalBrowser: NSObject) {\n print(\"External browser will open.\")\n}\n\nfunc linkOpenerWillOpen(inAppLink: NSObject) {\n print(\"In-app browser will open.\")\n}\n\nfunc linkOpenerDidOpen(inAppLink: NSObject) {\n print(\"In-app browser did open.\")\n}\n\nfunc linkOpenerWillClose(inAppLink: NSObject) {\n print(\"In-app browser will close.\")\n}\n\nfunc linkOpenerDidClose(inAppLink: NSObject) {\n print(\"In-app browser did close.\")\n}\n```\n\nObjective-C \n\n```objective-c\n- (void)linkOpenerWillOpenExternalBrowser:(NSObject *)linkOpener {\n NSLog(@\"External browser will open.\");\n}\n\n- (void)linkOpenerWillOpenInAppBrowser:(NSObject *)linkOpener {\n NSLog(@\"In-app browser will open.\");\n}\n\n- (void)linkOpenerDidOpenInAppBrowser:(NSObject *)linkOpener {\n NSLog(@\"In-app browser did open.\");\n}\n\n- (void)linkOpenerWillCloseInAppBrowser:(NSObject *)linkOpener {\n NSLog(@\"In-app browser will close.\");\n}\n\n- (void)linkOpenerDidCloseInAppBrowser:(NSObject *)linkOpener {\n NSLog(@\"In-app browser did close.\");\n}\n```"]]