From 82dc43b40fac7826120d19a19825f1491ae897bd Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Wed, 26 Mar 2025 22:12:18 +0900 Subject: [PATCH] =?UTF-8?q?pid=EB=A5=BC=20=EC=8B=AC=EC=96=B4=EB=86=93?= =?UTF-8?q?=EC=9D=80=20=EA=B4=91=EA=B3=A0=EB=A5=BC=20=ED=83=80=EA=B3=A0=20?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EC=98=A8=20=EA=B2=BD=EC=9A=B0=20=ED=95=AD?= =?UTF-8?q?=EC=83=81=20AppLaunch=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=ED=95=98=EB=8A=94=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SodaLive/Sources/App/AppDelegate.swift | 21 +++++++++ SodaLive/Sources/Tracking/AdTrackingApi.swift | 44 +++++++++++++++++++ .../Tracking/AdTrackingAppLaunchRequest.swift | 10 +++++ .../Tracking/AdTrackingRepository.swift | 19 ++++++++ 4 files changed, 94 insertions(+) create mode 100644 SodaLive/Sources/Tracking/AdTrackingApi.swift create mode 100644 SodaLive/Sources/Tracking/AdTrackingAppLaunchRequest.swift create mode 100644 SodaLive/Sources/Tracking/AdTrackingRepository.swift diff --git a/SodaLive/Sources/App/AppDelegate.swift b/SodaLive/Sources/App/AppDelegate.swift index 9301537..306664d 100644 --- a/SodaLive/Sources/App/AppDelegate.swift +++ b/SodaLive/Sources/App/AppDelegate.swift @@ -6,6 +6,7 @@ // import UIKit +import Combine import notifly_sdk import AppsFlyerLib @@ -17,6 +18,9 @@ import FirebaseMessaging class AppDelegate: UIResponder, UIApplicationDelegate { private let gcmMessageIDKey = "gcm.message_id" + private let adTrackingRepository = AdTrackingRepository() + + private var subscription = Set() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { FirebaseApp.configure() @@ -87,6 +91,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate { private func logUtmInFirebase() { FirebaseTracking.shared.logUtm() } + + private func adTrackingAppLaunch(pid: String) { + adTrackingRepository.adTrackingAppLaunch(pid: pid) + .sink { result in + switch result { + case .finished: + DEBUG_LOG("finish") + case .failure(let error): + ERROR_LOG(error.localizedDescription) + } + } receiveValue: { _ in + } + .store(in: &self.subscription) + + } } extension AppDelegate: AppsFlyerLibDelegate { @@ -96,6 +115,7 @@ extension AppDelegate: AppsFlyerLibDelegate { let pid = conversionInfo["deep_link_sub1"] as? String ?? "" if !pid.isEmpty { UserDefaults.set(pid, forKey: .marketingPid) + adTrackingAppLaunch(pid: pid) } if let utmSource = conversionInfo["deep_link_sub2"] as? String { @@ -155,6 +175,7 @@ extension AppDelegate: DeepLinkDelegate { let pid = deepLinkObj.clickEvent["deep_link_sub1"] as? String ?? "" if !pid.isEmpty { UserDefaults.set(pid, forKey: .marketingPid) + adTrackingAppLaunch(pid: pid) } if let utmSource = deepLinkObj.clickEvent["deep_link_sub2"] as? String { diff --git a/SodaLive/Sources/Tracking/AdTrackingApi.swift b/SodaLive/Sources/Tracking/AdTrackingApi.swift new file mode 100644 index 0000000..29e7305 --- /dev/null +++ b/SodaLive/Sources/Tracking/AdTrackingApi.swift @@ -0,0 +1,44 @@ +// +// AdTrackingApi.swift +// SodaLive +// +// Created by klaus on 3/26/25. +// + +import Foundation +import Moya + +enum AdTrackingApi { + case appLaunch(pid: String) +} + +extension AdTrackingApi: TargetType { + var baseURL: URL { + return URL(string: BASE_URL)! + } + + var path: String { + switch self { + case .appLaunch: + return "/ad-tracking/app-launch" + } + } + + var method: Moya.Method { + switch self { + case .appLaunch: + return .post + } + } + + var task: Moya.Task { + switch self { + case .appLaunch(let pid): + return .requestJSONEncodable(AdTrackingAppLaunchRequest(pid: pid)) + } + } + + var headers: [String : String]? { + return nil + } +} diff --git a/SodaLive/Sources/Tracking/AdTrackingAppLaunchRequest.swift b/SodaLive/Sources/Tracking/AdTrackingAppLaunchRequest.swift new file mode 100644 index 0000000..f4d56d0 --- /dev/null +++ b/SodaLive/Sources/Tracking/AdTrackingAppLaunchRequest.swift @@ -0,0 +1,10 @@ +// +// AdTrackingAppLaunchRequest.swift +// SodaLive +// +// Created by klaus on 3/26/25. +// + +struct AdTrackingAppLaunchRequest: Encodable { + let pid: String +} diff --git a/SodaLive/Sources/Tracking/AdTrackingRepository.swift b/SodaLive/Sources/Tracking/AdTrackingRepository.swift new file mode 100644 index 0000000..948afde --- /dev/null +++ b/SodaLive/Sources/Tracking/AdTrackingRepository.swift @@ -0,0 +1,19 @@ +// +// AdTrackingRepository.swift +// SodaLive +// +// Created by klaus on 3/26/25. +// + +import Foundation +import CombineMoya +import Combine +import Moya + +final class AdTrackingRepository { + private let api = MoyaProvider() + + func adTrackingAppLaunch(pid: String) -> AnyPublisher { + return api.requestPublisher(.appLaunch(pid: pid)) + } +}