如何设置应用程序以从 url iOS 接收 utm 参数?

how to setup the app for receiving the utm parameters from url iOS?

我想要帮助从 url 中检索 utm 参数,该应用已安装,但 url 中未收到 utm 参数。你们能帮忙设置应用程序以从应用程序接收 utm 参数吗?

这是我用来设置跟踪器和参数的代码

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool
{
    if let gai = GAI.sharedInstance(){
        gai.tracker(withTrackingId: AppConfiguration.GOOGLE_ANALYTICS_ID)
        gai.defaultTracker.allowIDFACollection = true
    }
}

从 url 安装应用程序时调用此方法:-

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {

    let urlString = url.absoluteString

    let tracker = GAI.sharedInstance().defaultTracker

    // setCampaignParametersFromUrl: parses Google Analytics campaign ("UTM")
    // parameters from a string url into a Map that can be set on a Tracker.
    let hitParams = GAIDictionaryBuilder()

    // Set campaign data on the map, not the tracker directly because it only
    // needs to be sent once.
    hitParams.setCampaignParametersFromUrl(urlString)

    // Campaign source is the only required campaign field. If previous call
    // did not set a campaign source, use the hostname as a referrer instead.
    if !(hitParams.get(kGAICampaignSource) != nil) && (url.host?.count ?? 0) != 0 {
        // Set campaign data on the map, not the tracker.
        hitParams.set("referrer", forKey: kGAICampaignMedium)
        hitParams.set(url.host, forKey: kGAICampaignSource)
    }
    //var hitParamsDict = hitParams.build()

    // A screen name is required for a screen view.
    tracker?.set(kGAIScreenName, value: "Sign up")
    var params = [AnyHashable : Any]()
    params[kGAICampaignMedium] = hitParams.get(kGAICampaignMedium)
    params[kGAICampaignSource] = hitParams.get(kGAICampaignSource)
    params[kGAICampaignContent] = hitParams.get(kGAICampaignContent)
    params[kGAICampaignName] = hitParams.get(kGAICampaignName)
    params[kGAICampaignKeyword] = hitParams.get(kGAICampaignKeyword)

    tracker?.send(params)

}

但 utm 参数未接收到应用程序。你们能帮忙吗...提前致谢

看看下面的代码。基本上,您创建 params hastable,在那里写入五个(或更少)参数,然后用它调用 tracker.send。您正在发送元数据,但没有发送实际点击(屏幕浏览或事件或..)。

// A screen name is required for a screen view.
tracker?.set(kGAIScreenName, value: "Sign up")
var params = [AnyHashable : Any]()
params[kGAICampaignMedium] = hitParams.get(kGAICampaignMedium)
params[kGAICampaignSource] = hitParams.get(kGAICampaignSource)
params[kGAICampaignContent] = hitParams.get(kGAICampaignContent)
params[kGAICampaignName] = hitParams.get(kGAICampaignName)
params[kGAICampaignKeyword] = hitParams.get(kGAICampaignKeyword)

tracker?.send(params)

文档 here 建议如下。请注意 [GAIDictionaryBuilder createScreenView] 调用。我相信这就是未提供活动数据的原因

[tracker send:[[[GAIDictionaryBuilder createScreenView] setAll:campaignData] build]];