Search code examples
iosswiftanalyticstrackingappsflyer

iOS - How to get params in One-Link of AppsFlyer. App was installed and launched


I can get params (campaign, media-source, etc...) of One-Link if my app does not install. I use the method below to do it.

func onConversionDataReceived(_ installData: [AnyHashable : Any]!) {

    if let data = installData{

        print("\(data)")

        if let status = data["af_status"] as? String{

            if(status == "Non-organic"){

                if let sourceID = data["media_source"] , let campaign = data["campaign"]{

                    print("This is a Non-Organic install. Media source: \(sourceID)  Campaign: \(campaign)")

                }

            } else {

                print("This is an organic install.")

            }

        }

    }

}

But if my app was installed, launched and then I click on another One-Link to open my app, I just get only this URL by the method below:

func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]!) {

    if let data = attributionData{

        print("\(data)")

    }

}

So have any way to get params (campaign, media-source, etc...) in case my app available on a device?

Note: I used a short link.


Solution

  • onAppOpenAttribution is triggered every time you open the app from different deep-link (In your case the One-Link).

    I can get params (campaign, media-source, etc...) of One-Link if my app does not install.

    Right, 1st time the two callbacks are triggered onAppOpenAttribution and onConversionDataReceived.

    But if my app was installed, launched and then I click on another One-Link to open my app

    It can happen if you try to open the app from One-Link that not belongs to Appsflyer.

    For example, this link (Universal Link) https://rndemotest.onelink.me/7y5s/f78c46d5 will give you a media source, campaign etc. through onAppOpenAttribution, where 7y5s is your One-Link ID defined in "ONELINK CONFIGURATION" section of the dashboard.

    [EDIT]

    Be sure you run latest AppsFlyer SDK version,

    Deep linking with short links for iOS Universal Links or Android App Links is only supported from SDK version 4.8.0

    Generally, you should get a response as {"link": "<URL>"} for Full link a.e. {"link":"https://abc.onelink.me/2347196006?pid=User%20invite&c=CMTT2019einvite&af_dp=abc%3A%2F%2F"}

    For One-Link, you should get all inforamtion contains media source, ... .


    BTW here is a code snippet example how to handle onAppOpenAttribution response:

    func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]!) {
    
            var attDataString:String = ""
            var params = [String: String]()
    
            print("")
            print("<-------------------------------------------------->")
            print("onAppOpenAttribution is:")
    
            if let pid = attributionData[AnyHashable("pid")] as? String{
                attDataString.append("PID: " + pid + "\n\n")
                print(helper(module: "pid", message: pid))
            }
    
            if let is_retargeting = attributionData[AnyHashable("is_retargeting")] as? String{
                attDataString.append("is_retargeting: " + is_retargeting + "\n\n")
                print(helper(module: "is_retargeting", message: is_retargeting))
            }
    
            if let campaign = attributionData[AnyHashable("c")] as? String{
                attDataString.append("Campaign: " + campaign + "\n\n")
                print(helper(module: "campaign", message: campaign))
            }
    
            if let link = attributionData[AnyHashable("link")] as? String{
                attDataString.append("Link: " + link + "\n\n")
                print(helper(module: "link", message: link))
            }
    
            if let af_dp = attributionData[AnyHashable("af_dp")] as? String{
                attDataString.append("af_dp: " + af_dp + "\n\n")
                print(helper(module: "af_dp", message: af_dp))
            }
            print(attributionData)
            print("<-------------------------------------------------->")
            print("")
    
            //        dump(attributionData)
        }
    
    func helper(module:String!, message:String!) -> String!{
    
            var sb:String = ""
            sb.append(" " + module + "=")
            var pad:Int = 17 - module.characters.count
    
            while  pad > 0 {
                pad-=1
                sb.append( " " )
            }
            sb.append(" " + message)
    
            return sb
        }