앱스플라이어 딥링크 설정

This commit is contained in:
Yu Sung 2025-03-06 15:13:26 +09:00
parent d019f44a0e
commit d7c8f4ad40
5 changed files with 48 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import UIKit
import AppsFlyerLib import AppsFlyerLib
import FBSDKCoreKit import FBSDKCoreKit
import FirebaseCore import FirebaseCore
import FirebaseAnalytics
import FirebaseMessaging import FirebaseMessaging
class AppDelegate: UIResponder, UIApplicationDelegate { class AppDelegate: UIResponder, UIApplicationDelegate {
@ -79,6 +80,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
AppsFlyerLib.shared().delegate = self AppsFlyerLib.shared().delegate = self
AppsFlyerLib.shared().deepLinkDelegate = 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 { extension AppDelegate: AppsFlyerLibDelegate {
@ -109,14 +124,25 @@ extension AppDelegate: DeepLinkDelegate {
return return
} }
if(deepLinkObj.isDeferred == true) { UserDefaults.set(deepLinkObj.clickEvent["deep_link_sub1"] as? String ?? "", forKey: .marketingPid)
DEBUG_LOG("[AFSDK] This is a deferred deep link") AppState.shared.marketingUtmSource = deepLinkObj.clickEvent["deep_link_sub2"] as? String ?? ""
} AppState.shared.marketingUtmMedium = deepLinkObj.clickEvent["deep_link_sub3"] as? String ?? ""
else { AppState.shared.marketingUtmCampaign = deepLinkObj.clickEvent["deep_link_sub4"] as? String ?? ""
DEBUG_LOG("[AFSDK] This is a direct deep link")
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()
} }
} }

View File

@ -29,6 +29,7 @@ class AppState: ObservableObject {
@Published var pushChannelId = 0 @Published var pushChannelId = 0
@Published var pushMessageId = 0 @Published var pushMessageId = 0
@Published var pushAudioContentId = 0 @Published var pushAudioContentId = 0
@Published var pushSeriesId = 0
@Published var roomId = 0 { @Published var roomId = 0 {
didSet { didSet {
if roomId <= 0 { if roomId <= 0 {
@ -44,6 +45,10 @@ class AppState: ObservableObject {
@Published var isChangeAdultContentVisible = false @Published var isChangeAdultContentVisible = false
@Published var startTab: HomeViewModel.CurrentTab = .content @Published var startTab: HomeViewModel.CurrentTab = .content
@Published var marketingUtmSource = ""
@Published var marketingUtmMedium = ""
@Published var marketingUtmCampaign = ""
func setAppStep(step: AppStep) { func setAppStep(step: AppStep) {
switch step { switch step {
case .splash, .main: case .splash, .main:

View File

@ -27,6 +27,7 @@ enum UserDefaultsKey: String, CaseIterable {
case contentPreference case contentPreference
case isAuditionNotification case isAuditionNotification
case searchChannel case searchChannel
case marketingPid
} }
extension UserDefaults { extension UserDefaults {

View File

@ -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 { .onAppear {
if appState.pushMessageId > 0 { if appState.pushMessageId > 0 {
viewModel.currentTab = .message viewModel.currentTab = .message

View File

@ -102,6 +102,8 @@ struct SplashView: View {
AppState.shared.setAppStep(step: .creatorDetail(userId: AppState.shared.pushChannelId)) AppState.shared.setAppStep(step: .creatorDetail(userId: AppState.shared.pushChannelId))
} else if AppState.shared.pushAudioContentId > 0 { } else if AppState.shared.pushAudioContentId > 0 {
AppState.shared.setAppStep(step: .contentDetail(contentId: AppState.shared.pushAudioContentId)) 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 { } else {
AppState.shared.setAppStep(step: .main) AppState.shared.setAppStep(step: .main)
} }