控制用户点击事件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南介绍了如何在 IMA SDK 实现中更好地控制点击。“点击”是指用户点击广告并进入该广告的着陆页的过程。本指南中的示例演示了如何配置着陆页的打开位置,以及如何监听与用户访问该页面相关的事件。
前提条件
已实现 IMA SDK 的 iOS 应用。
配置点击
更改链接打开方式
IMA SDK 提供了两种打开广告着陆页的选项:通过应用内浏览器或通过 Safari。默认情况下,SDK 使用 Safari 打开网页。如需更新 SDK 以使用应用内浏览器,您需要使用
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;
}
配置
IMAAdsRenderingSettings
实例后,您可以将其传递给
IMAAdsManager
初始化方法:
Swift
self.adsManager.initialize(withAdsRenderingSettings: adsRenderingSettings);
Objective-C
[self.adsManager initializeWithAdsRenderingSettings:adsRenderingSettings];
IMA SDK 提供
IMALinkOpenerDelegate
,用于在用户即将看到或刚刚关闭点击到达页面时进行通信。如需使用此代理,请将其添加到头文件中的代理列表,并实现其方法。在标题中:
Swift
class ViewController: UIViewController, IMALinkOpenerDelegate {
Objective-C
@interface ViewController : UIViewController<IMALinkOpenerDelegate>
在实现中:
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.");
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\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```"]]