Skip to content

Commit cec865f

Browse files
authored
added in segDelegate and segDLDelegate so that we could have callbacks to the calling app. (#9)
1 parent cf4b1bf commit cec865f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

Sources/SegmentAppsFlyer/AppsFlyerDestination.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,26 @@ public class AppsFlyerDestination: UIResponder, DestinationPlugin {
4646
public var analytics: Analytics?
4747

4848
fileprivate var settings: AppsFlyerSettings? = nil
49-
49+
50+
private weak var segDelegate: AppsFlyerLibDelegate?
51+
private weak var segDLDelegate: DeepLinkDelegate?
52+
53+
// MARK: - Initialization
54+
55+
/// Creates and returns an AppsFlyer destination plugin for the Segment SDK
56+
///
57+
/// See ``AppsFlyerDestination`` for more information
58+
///
59+
/// - Parameters:
60+
/// - segDelegate: When provided, this delegate will get called back for all AppsFlyerDelegate methods - ``onConversionDataSuccess(_:)``, ``onConversionDataFail(_:)``, ``onAppOpenAttribution(_:)``, ``onAppOpenAttributionFailure(_:)``
61+
/// - segDLDelegate: When provided, this delegate will get called back for all DeepLinkDelegate routines, or just ``didResolveDeeplink``
62+
public init(segDelegate: AppsFlyerLibDelegate? = nil,
63+
segDLDelegate: DeepLinkDelegate? = nil) {
64+
self.segDelegate = segDelegate
65+
self.segDLDelegate = segDLDelegate
66+
}
67+
68+
// MARK: - Plugin
5069
public func update(settings: Settings, type: UpdateType) {
5170
// we've already set up this singleton SDK, can't do it again, so skip.
5271
guard type == .initial else { return }
@@ -186,6 +205,7 @@ extension AppsFlyerDestination: AppsFlyerLibDelegate {
186205
}
187206

188207
if (firstLaunchFlag == 1) {
208+
segDelegate?.onConversionDataSuccess(conversionInfo)
189209
if (status == "Non-organic") {
190210
if let mediaSource = conversionInfo["media_source"] , let campaign = conversionInfo["campaign"], let adgroup = conversionInfo["adgroup"]{
191211

@@ -213,12 +233,12 @@ extension AppsFlyerDestination: AppsFlyerLibDelegate {
213233
}
214234

215235
public func onConversionDataFail(_ error: Error) {
216-
236+
segDelegate?.onConversionDataFail(error)
217237
}
218238

219239

220240
public func onAppOpenAttribution(_ attributionData: [AnyHashable: Any]) {
221-
241+
segDelegate?.onAppOpenAttribution?(attributionData)
222242
if let media_source = attributionData["media_source"] , let campaign = attributionData["campaign"],
223243
let referrer = attributionData["http_referrer"] {
224244

@@ -241,7 +261,7 @@ extension AppsFlyerDestination: AppsFlyerLibDelegate {
241261

242262

243263
public func onAppOpenAttributionFailure(_ error: Error) {
244-
264+
segDelegate?.onAppOpenAttributionFailure?(error)
245265
}
246266
}
247267

@@ -256,6 +276,7 @@ extension AppsFlyerDestination: VersionedPlugin {
256276
extension AppsFlyerDestination: DeepLinkDelegate, UIApplicationDelegate {
257277

258278
public func didResolveDeepLink(_ result: DeepLinkResult) {
279+
segDLDelegate?.didResolveDeepLink?(result)
259280
switch result.status {
260281
case .notFound:
261282
return

0 commit comments

Comments
 (0)