diff --git a/SodaLive/Sources/App/AppDelegate.swift b/SodaLive/Sources/App/AppDelegate.swift index 8b205c9..926a22e 100644 --- a/SodaLive/Sources/App/AppDelegate.swift +++ b/SodaLive/Sources/App/AppDelegate.swift @@ -10,6 +10,7 @@ import UIKit import AppsFlyerLib import FBSDKCoreKit import FirebaseCore +import FirebaseAnalytics import FirebaseMessaging class AppDelegate: UIResponder, UIApplicationDelegate { @@ -79,6 +80,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate { AppsFlyerLib.shared().delegate = self AppsFlyerLib.shared().deepLinkDelegate = self } + + private func logUtmInFirebase() { + let utmSource = AppState.shared.marketingUtmSource.trimmingCharacters(in: .whitespacesAndNewlines) + let utmMedium = AppState.shared.marketingUtmMedium.trimmingCharacters(in: .whitespacesAndNewlines) + let utmCampaign = AppState.shared.marketingUtmCampaign.trimmingCharacters(in: .whitespacesAndNewlines) + + if !utmSource.isEmpty && !utmMedium.isEmpty && !utmCampaign.isEmpty { + Analytics.logEvent("campaign_utm", parameters: [ + "utm_source": utmSource, + "utm_medium": utmMedium, + "utm_campaign": utmCampaign + ]) + } + } } extension AppDelegate: AppsFlyerLibDelegate { @@ -109,14 +124,25 @@ extension AppDelegate: DeepLinkDelegate { return } - if(deepLinkObj.isDeferred == true) { - DEBUG_LOG("[AFSDK] This is a deferred deep link") - } - else { - DEBUG_LOG("[AFSDK] This is a direct deep link") + UserDefaults.set(deepLinkObj.clickEvent["deep_link_sub1"] as? String ?? "", 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 ?? "" + + + let deepLinkValue = deepLinkObj.clickEvent["deep_link_value"] as? String ?? "" + + if deepLinkValue == "series" { + AppState.shared.pushSeriesId = deepLinkObj.clickEvent["deep_link_sub5"] as? Int ?? 0 + } else if deepLinkValue == "content" { + AppState.shared.pushAudioContentId = deepLinkObj.clickEvent["deep_link_sub5"] as? Int ?? 0 + } else if deepLinkValue == "live" { + AppState.shared.pushRoomId = deepLinkObj.clickEvent["deep_link_sub5"] as? Int ?? 0 + } else if deepLinkValue == "channel" { + AppState.shared.pushChannelId = deepLinkObj.clickEvent["deep_link_sub5"] as? Int ?? 0 } - DEBUG_LOG("deepLinkValue: \(deepLinkObj.deeplinkValue ?? "")") + logUtmInFirebase() } } diff --git a/SodaLive/Sources/App/AppState.swift b/SodaLive/Sources/App/AppState.swift index 3f6c965..2660dce 100644 --- a/SodaLive/Sources/App/AppState.swift +++ b/SodaLive/Sources/App/AppState.swift @@ -29,6 +29,7 @@ class AppState: ObservableObject { @Published var pushChannelId = 0 @Published var pushMessageId = 0 @Published var pushAudioContentId = 0 + @Published var pushSeriesId = 0 @Published var roomId = 0 { didSet { if roomId <= 0 { @@ -44,6 +45,10 @@ class AppState: ObservableObject { @Published var isChangeAdultContentVisible = false @Published var startTab: HomeViewModel.CurrentTab = .content + @Published var marketingUtmSource = "" + @Published var marketingUtmMedium = "" + @Published var marketingUtmCampaign = "" + func setAppStep(step: AppStep) { switch step { case .splash, .main: diff --git a/SodaLive/Sources/Extensions/UserDefaultsExtension.swift b/SodaLive/Sources/Extensions/UserDefaultsExtension.swift index 2865723..2390b4b 100644 --- a/SodaLive/Sources/Extensions/UserDefaultsExtension.swift +++ b/SodaLive/Sources/Extensions/UserDefaultsExtension.swift @@ -27,6 +27,7 @@ enum UserDefaultsKey: String, CaseIterable { case contentPreference case isAuditionNotification case searchChannel + case marketingPid } extension UserDefaults { diff --git a/SodaLive/Sources/Main/Home/HomeView.swift b/SodaLive/Sources/Main/Home/HomeView.swift index 3028c93..f39f88f 100644 --- a/SodaLive/Sources/Main/Home/HomeView.swift +++ b/SodaLive/Sources/Main/Home/HomeView.swift @@ -269,6 +269,14 @@ struct HomeView: View { } } } + .valueChanged(value: appState.pushSeriesId) { value in + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + if value > 0 { + appState.setAppStep(step: .main) + appState.setAppStep(step: .seriesDetail(seriesId: value)) + } + } + } .onAppear { if appState.pushMessageId > 0 { viewModel.currentTab = .message diff --git a/SodaLive/Sources/Splash/SplashView.swift b/SodaLive/Sources/Splash/SplashView.swift index 0e30c05..eb841af 100644 --- a/SodaLive/Sources/Splash/SplashView.swift +++ b/SodaLive/Sources/Splash/SplashView.swift @@ -102,6 +102,8 @@ struct SplashView: View { AppState.shared.setAppStep(step: .creatorDetail(userId: AppState.shared.pushChannelId)) } else if AppState.shared.pushAudioContentId > 0 { AppState.shared.setAppStep(step: .contentDetail(contentId: AppState.shared.pushAudioContentId)) + } else if AppState.shared.pushSeriesId > 0 { + AppState.shared.setAppStep(step: .seriesDetail(seriesId: AppState.shared.pushSeriesId)) } else { AppState.shared.setAppStep(step: .main) }