Kiểm soát sự kiện nhấp chuột của người dùng
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hướng dẫn này giải thích cách triển khai quyền kiểm soát nhiều hơn đối với lượt nhấp trong quá trình triển khai SDK IMA. "Lượt nhấp" là quá trình người dùng nhấp vào một quảng cáo và chuyển đến trang đích của quảng cáo đó. Các ví dụ trong hướng dẫn này minh hoạ cách định cấu hình vị trí mở trang đích đó và cách theo dõi các sự kiện liên quan đến người dùng truy cập vào trang đó.
Điều kiện tiên quyết
Một ứng dụng iOS đã triển khai SDK IMA.
Định cấu hình lượt nhấp
Thay đổi trình mở đường liên kết
SDK IMA cung cấp hai lựa chọn để mở trang đích quảng cáo – thông qua trình duyệt trong ứng dụng hoặc thông qua Safari. Theo mặc định, SDK sẽ mở các trang bằng Safari. Để cập nhật SDK để sử dụng trình duyệt trong ứng dụng, bạn cần sử dụng
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;
}
Sau khi định cấu hình thực thể
IMAAdsRenderingSettings
, bạn có thể truyền thực thể đó đến phương thức khởi chạy
IMAAdsManager
:
Swift
self.adsManager.initialize(withAdsRenderingSettings: adsRenderingSettings);
Objective-C
[self.adsManager initializeWithAdsRenderingSettings:adsRenderingSettings];
SDK IMA cung cấp
IMALinkOpenerDelegate
để giao tiếp khi người dùng sắp xem hoặc vừa đóng một trang nhấp chuột. Để sử dụng trình uỷ quyền này, hãy thêm trình uỷ quyền vào danh sách trình uỷ quyền trong tiêu đề và triển khai các phương thức của trình uỷ quyền. Trong tiêu đề:
Swift
class ViewController: UIViewController, IMALinkOpenerDelegate {
Objective-C
@interface ViewController : UIViewController<IMALinkOpenerDelegate>
Và trong quá trình triển khai:
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.");
}
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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```"]]