Integrating Ads
- Print
Integrating Ads
- Print
Article summary
Did you find this summary helpful?    
Thank you for your feedback!
When passing through multiple advertising channels, you can maintain continuous tracking by appending query parameters to the deeplink or web link address.
The following example assumes an inbound request from a deeplink
Passing Query Parameters with the ShopLive SDK
class SceneDelegate: UIResponder, UIWindowSceneDelegate { 
    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let urlContext = URLContexts.first else { return }
        let url = urlContext.url
        handleUrl(url : url)
    }
    func handleUrl(url : URL) {
        // 1. Break down the URL using URLComponents
        guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
              let queryItems = components.queryItems else {
            print("No query parameters found.")
            return
        }
        // 2. Convert to [String: String] format
        let params: [String: String] = queryItems.reduce(into: [:]) { result, item in
            result[item.name] = item.value ?? ""
        }
        // 3. Set the query parameters required for ad integration in the ShopLive SDK
        for (key,value) in params {
             if key == "utm_source" {
                 ShopLiveCommon.setUtmSource(utmSource: value)
             }
             else if key == "utm_medium" {
                 ShopLiveCommon.setUtmMedium(utmMedium: value)
             }
             else if key == "utm_campaign" {
                 ShopLiveCommon.setUtmCampaign(utmCampaign: value)
             }
             else if key == "utm_content" {
                 ShopLiveCommon.setUtmContent(utmContent: value)
             }
             else {
                 ShopLive.addParameter(key: key, value: value)
             }
        }
        ShopLive.play()
    }
}
.png)