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)) + } +}