技术咨询:能否通过Google UAC为iOS应用安装广告系列传递深度链接数据
能否通过Google UAC在iOS应用安装广告中传递深度链接数据?
没问题!Google UAC(通用应用广告系列)完全支持在iOS应用安装广告里传递自定义深度链接数据——包括你需要的每个广告系列唯一标识符,而且能在应用首次启动时顺利读取到这些信息。我来给你唠唠具体怎么操作:
一、在UAC广告后台配置深度链接
首先得在Google Ads后台给你的UAC广告系列设置好深度链接:
- 进入广告系列编辑页面,找到深度链接设置板块:
- 选择「应用深度链接」,填入你的自定义链接格式,比如
yourapp://install?campaign_id=你的唯一标识符,这里的campaign_id就是你要传递的专属标识,每个广告系列可以设置不同的值 - 要是你用的是App Store链接,也可以加UTM参数,但更推荐用自定义深度链接——毕竟UTM参数在App Store跳转过程中偶尔会被截断,深度链接的可靠性更高
- 选择「应用深度链接」,填入你的自定义链接格式,比如
- 划重点:你的iOS应用必须先配置好对应的URL Scheme或者Universal Links,不然没法识别并处理这个链接哦
二、在iOS应用里读取深度链接参数
用户通过广告安装并首次启动应用时,你需要在合适的地方抓取这些参数,分两种场景:
1. iOS 13及以前(用UIApplicationDelegate)
在application(_:open:options:)或者application(_:continue:restorationHandler:)方法里解析链接:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { // 解析URL里的参数 guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true), let campaignId = components.queryItems?.first(where: { $0.name == "campaign_id" })?.value else { return false } // 把拿到的唯一标识符存起来,比如存到UserDefaults或者直接上传到你的服务器 UserDefaults.standard.set(campaignId, forKey: "install_campaign_id") return true }
2. iOS 13+(用SceneDelegate)
在scene(_:openURLContexts:)方法中处理:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { guard let url = URLContexts.first?.url else { return } if let components = URLComponents(url: url, resolvingAgainstBaseURL: true), let campaignId = components.queryItems?.first(where: { $0.name == "campaign_id" })?.value { UserDefaults.standard.set(campaignId, forKey: "install_campaign_id") } }
小技巧:判断首次启动
如果你只想在首次安装启动时处理这个参数,可以结合UserDefaults做个标记:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let hasLaunchedBefore = UserDefaults.standard.bool(forKey: "has_launched_before") if !hasLaunchedBefore { // 标记为已启动过,避免重复处理 UserDefaults.standard.set(true, forKey: "has_launched_before") // 如果是直接通过深度链接启动的,这里可以补充处理逻辑 } return true }
三、特殊情况:通过App Store安装后的归因
如果用户是点击广告跳转到App Store安装应用,首次启动时可能不会直接触发深度链接(毕竟中间隔了App Store),这时候就得靠Google的归因工具了:
你可以集成Google Analytics for Firebase SDK,通过它来获取广告归因数据:
- 把Firebase SDK集成到你的iOS应用里
- 在Google Ads后台开启「Firebase链接」
- 在应用里调用API获取归因信息:
import FirebaseAnalytics func fetchCampaignAttribution() { Analytics.appInstallAttribution { attributionDict, error in guard let attribution = attributionDict, error == nil else { return } // 从归因数据里提取你设置的campaign标识符 if let campaignId = attribution["campaign_id"] as? String { // 这里就可以使用这个唯一标识啦 } } }
内容的提问来源于stack exchange,提问作者user2537358
相关产品推荐
相关产品推荐

