diff --git a/SodaLive/Sources/App/AppDelegate.swift b/SodaLive/Sources/App/AppDelegate.swift index 21e04fb..9301537 100644 --- a/SodaLive/Sources/App/AppDelegate.swift +++ b/SodaLive/Sources/App/AppDelegate.swift @@ -92,6 +92,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate { extension AppDelegate: AppsFlyerLibDelegate { func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) { DEBUG_LOG("AppsFlyer Conversion Data: \(conversionInfo)") + if let status = conversionInfo["af_status"] as? String, status == "Non-organic" { + let pid = conversionInfo["deep_link_sub1"] as? String ?? "" + if !pid.isEmpty { + UserDefaults.set(pid, forKey: .marketingPid) + } + + if let utmSource = conversionInfo["deep_link_sub2"] as? String { + AppState.shared.marketingUtmSource = utmSource + } + + if let utmMedium = conversionInfo["deep_link_sub3"] as? String { + AppState.shared.marketingUtmMedium = utmMedium + } + + if let utmCampaign = conversionInfo["deep_link_sub4"] as? String { + AppState.shared.marketingUtmCampaign = utmCampaign + } + + let deepLinkValue = conversionInfo["deep_link_value"] as? String ?? "" + let deepLinkValueId = Int(conversionInfo["deep_link_sub5"] as? String ?? "") ?? 0 + + if deepLinkValueId > 0 { + if deepLinkValue == "series" { + AppState.shared.pushSeriesId = deepLinkValueId + } else if deepLinkValue == "content" { + AppState.shared.pushAudioContentId = deepLinkValueId + } else if deepLinkValue == "live" { + AppState.shared.pushRoomId = deepLinkValueId + } else if deepLinkValue == "channel" { + AppState.shared.pushChannelId = deepLinkValueId + } + } + + logUtmInFirebase() + } } func onConversionDataFail(_ error: any Error) { @@ -122,9 +157,17 @@ extension AppDelegate: DeepLinkDelegate { UserDefaults.set(pid, forKey: .marketingPid) } - AppState.shared.marketingUtmSource = deepLinkObj.clickEvent["deep_link_sub2"] as? String ?? "" - AppState.shared.marketingUtmMedium = deepLinkObj.clickEvent["deep_link_sub3"] as? String ?? "" - AppState.shared.marketingUtmCampaign = deepLinkObj.clickEvent["deep_link_sub4"] as? String ?? "" + if let utmSource = deepLinkObj.clickEvent["deep_link_sub2"] as? String { + AppState.shared.marketingUtmSource = utmSource + } + + if let utmMedium = deepLinkObj.clickEvent["deep_link_sub3"] as? String { + AppState.shared.marketingUtmMedium = utmMedium + } + + if let utmCampaign = deepLinkObj.clickEvent["deep_link_sub4"] as? String { + AppState.shared.marketingUtmCampaign = utmCampaign + } let deepLinkValue = deepLinkObj.clickEvent["deep_link_value"] as? String ?? "" let deepLinkValueId = Int(deepLinkObj.clickEvent["deep_link_sub5"] as? String ?? "") ?? 0