앱스플라이어 딥링크 설정
This commit is contained in:
		| @@ -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() | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -27,6 +27,7 @@ enum UserDefaultsKey: String, CaseIterable { | ||||
|     case contentPreference | ||||
|     case isAuditionNotification | ||||
|     case searchChannel | ||||
|     case marketingPid | ||||
| } | ||||
|  | ||||
| extension UserDefaults { | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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) | ||||
|                         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Yu Sung
					Yu Sung