@@ -29,7 +29,7 @@ import Traceback
2929lazy var traceback: TracebackSDK = {
3030 let config = TracebackConfiguration (
3131 mainAssociatedHost : URL (string : " https://your-project-traceback.firebaseapp.com" )! ,
32- useClipboard : true ,
32+ useClipboard : false ,
3333 logLevel : .error
3434 )
3535 return TracebackSDK.live (config : config)
@@ -51,7 +51,7 @@ let config = TracebackConfiguration(
5151 associatedHosts : [
5252 URL (string : " https://your-custom-domain.com" )!
5353 ],
54- useClipboard : true ,
54+ useClipboard : false ,
5555 logLevel : .debug
5656)
5757```
@@ -69,35 +69,52 @@ struct PreLandingView: View {
6969 /* ... */
7070 .onAppear {
7171 Task {
72- // 1.- Search for post-install link and proceed if available
73- guard let result = try ? await traceback.postInstallSearchLink (),
74- let tracebackURL = result.url else {
75- return
72+ do {
73+ // 1.- Search for post-install link and proceed if available
74+ let result = try await traceback.postInstallSearchLink ()
75+ if let tracebackURL = result.url {
76+ proceed (onOpenURL : tracebackURL)
77+ }
78+ } catch {
79+ // Handle error - network issues, configuration problems, etc.
80+ logger.error (" Failed to search for post-install link: \( error ) " )
7681 }
77- proceed (onOpenURL : tracebackURL)
7882 }
7983 }
8084 .onOpenURL { url in
8185 proceed (onOpenURL : url)
8286 }
8387 }
84-
88+
8589 // This method is to be called from onOpenURL or after post install link search
86- func proceed (
87- onOpenURL : URL
88- ) {
89- // 2.- Grab the correct url
90- // URL is either a post-install link (detected after app download on onAppear above),
91- // or an opened url (direct open in installed app)
92- guard let linkResult = try ? traceback.extractLinkFromURL (url),
93- let linkURL = linkResult.url else {
94- return assertionFailure (" Could not find a valid traceback/universal url in \( url ) " )
90+ func proceed (onOpenURL url : URL) {
91+ // 2.- Check if this is a Traceback URL
92+ guard traceback.isTracebackURL (url) else {
93+ // Not a Traceback URL, handle it elsewhere
94+ handleDeepLink (linkURL)
95+ return
96+ }
97+
98+ Task {
99+ do {
100+ // 3.- Check if dynamic campaign link exists (resolves the deep link from the URL)
101+ let linkResult = try await traceback.campaignSearchLink (url)
102+
103+ guard let linkURL = linkResult.url else {
104+ // No deep link found in this URL, so we normally continue opening the app Landing screen
105+ return
106+ }
107+
108+ // 4.- Handle the url, opening the right content indicated by linkURL
109+ // Use linkURL to navigate to the appropriate content in your app
110+ // You can also access linkResult.analytics for tracking purposes
111+ handleDeepLink (linkURL)
112+ sendAnalytics (linkResult.analytics )
113+ } catch {
114+ // Handle error - network issues, invalid URL, etc.
115+ logger.error (" Failed to resolve campaign link: \( error ) " )
116+ }
95117 }
96-
97- // 3.- Handle the url, opening the right content indicated by linkURL
98- // Use linkURL to navigate to the appropriate content in your app
99- // You can also access linkResult.analytics for tracking purposes
100- YOUR CODE HERE
101118 }
102119}
103120```
@@ -114,13 +131,17 @@ class YourAppDelegate: NSObject, UIApplicationDelegate {
114131 didFinishLaunchingWithOptions launchOptions : [UIApplication.LaunchOptionsKey : Any ]? = nil
115132 ) -> Bool {
116133 Task {
117- // 1.- Trigger a search for installation links
118- // if a link is found successfully, it will be sent to proceed(openURL:) below
119- guard let result = try ? await traceback.postInstallSearchLink (),
120- let tracebackURL = result.url else {
121- return
134+ do {
135+ // 1.- Trigger a search for installation links
136+ // if a link is found successfully, it will be sent to proceed(openURL:) below
137+ let result = try await traceback.postInstallSearchLink ()
138+ if let tracebackURL = result.url {
139+ proceed (onOpenURL : tracebackURL)
140+ }
141+ } catch {
142+ // Handle error - network issues, configuration problems, etc.
143+ logger.error (" Failed to search for post-install link: \( error ) " )
122144 }
123- proceed (onOpenURL : tracebackURL)
124145 }
125146 return true
126147 }
@@ -135,23 +156,36 @@ class YourAppDelegate: NSObject, UIApplicationDelegate {
135156 proceed (onOpenURL : url)
136157 return true
137158 }
138-
159+
139160 // This method is to be called from application(open:options:) or after post install link search
140- func proceed (
141- onOpenURL : URL
142- ) {
143- // 2.- Grab the correct url
144- // URL is either a post-install link (detected after app launch above),
145- // or an opened url (direct open in installed app)
146- guard let linkResult = try ? traceback.extractLinkFromURL (url),
147- let linkURL = linkResult.url else {
148- return assertionFailure (" Could not find a valid traceback/universal url in \( url ) " )
161+ func proceed (onOpenURL url : URL) {
162+ // 2.- Check if this is a Traceback URL
163+ guard traceback.isTracebackURL (url) else {
164+ // Not a Traceback URL, handle it elsewhere
165+ handleDeepLink (linkURL)
166+ return
167+ }
168+
169+ Task {
170+ do {
171+ // 3.- Check if dynamic campaign link exists (resolves the deep link from the URL)
172+ let linkResult = try await traceback.campaignSearchLink (url)
173+
174+ guard let linkURL = linkResult.url else {
175+ // No deep link found in this URL, so we normally continue opening the app Landing screen
176+ return
177+ }
178+
179+ // 4.- Handle the url, opening the right content indicated by linkURL
180+ // Use linkURL to navigate to the appropriate content in your app
181+ // You can also access linkResult.analytics for tracking purposes
182+ handleDeepLink (linkURL)
183+ sendAnalytics (linkResult.analytics )
184+ } catch {
185+ // Handle error - network issues, invalid URL, etc.
186+ logger.error (" Failed to resolve campaign link: \( error ) " )
187+ }
149188 }
150-
151- // 3.- Handle the url, opening the right content indicated by linkURL
152- // Use linkURL to navigate to the appropriate content in your app
153- // You can also access linkResult.analytics for tracking purposes
154- YOUR CODE HERE
155189 }
156190}
157191```
@@ -191,12 +225,26 @@ The diagnostics will categorize issues as:
191225
192226## API Reference
193227
228+ ### TracebackSDK Methods
229+
230+ #### ` postInstallSearchLink() async throws -> TracebackSDK.Result `
231+ Searches for the deep link that triggered the app installation. Call this once during app launch.
232+
233+ #### ` campaignSearchLink(_ url: URL) async throws -> TracebackSDK.Result `
234+ Resolves a Traceback URL opened via Universal Link or custom URL scheme into a deep link.
235+
236+ #### ` isTracebackURL(_ url: URL) -> Bool `
237+ Validates if the given URL matches any of the configured Traceback domains.
238+
239+ #### ` performDiagnostics() `
240+ Runs comprehensive validation of your Traceback configuration and outputs diagnostic information.
241+
194242### TracebackSDK.Result
195243
196- The result object returned by ` postInstallSearchLink() ` and ` extractLinkFromURL ()` contains:
244+ The result object returned by ` postInstallSearchLink() ` and ` campaignSearchLink ()` contains:
197245
198246- ` url: URL? ` - The extracted deep link URL to navigate to
199- - ` matchType: MatchType ` - How the link was detected (` .unique ` , ` .heuristics ` , ` .ambiguous ` , ` .intent ` , ` .none ` )
247+ - ` matchType: MatchType ` - How the link was detected (` .unique ` , ` .heuristics ` , ` .ambiguous ` , ` .intent ` , ` .none ` , ` .unknown ` )
200248- ` analytics: [TracebackAnalyticsEvent] ` - Analytics events you can send to your preferred platform
201249
202250### TracebackConfiguration
@@ -220,14 +268,18 @@ public struct TracebackConfiguration {
220268
221269## Error Handling
222270
223- The SDK uses Swift's error handling mechanisms:
271+ The SDK uses Swift's error handling mechanisms. Both ` postInstallSearchLink() ` and ` campaignSearchLink() ` can throw errors:
272+
273+ ### Post-Install Link Search
224274
225275``` swift
226276do {
227277 let result = try await traceback.postInstallSearchLink ()
228278 if let url = result.url {
229279 // Handle successful link detection
230280 handleDeepLink (url)
281+ // Send analytics events
282+ sendAnalytics (result.analytics )
231283 } else {
232284 // No link found - normal app startup
233285 handleNormalStartup ()
@@ -239,6 +291,26 @@ do {
239291}
240292```
241293
294+ ### Campaign Link Resolution
295+
296+ ``` swift
297+ do {
298+ let result = try await traceback.campaignSearchLink (url)
299+ if let deepLink = result.url {
300+ // Handle successful link resolution
301+ handleDeepLink (deepLink)
302+ // Send analytics events
303+ sendAnalytics (result.analytics )
304+ } else {
305+ // URL is valid Traceback URL but no deep link found
306+ handleNormalStartup ()
307+ }
308+ } catch {
309+ // Handle network or configuration errors
310+ logger.error (" Failed to resolve campaign link: \( error ) " )
311+ }
312+ ```
313+
242314## Troubleshooting
243315
244316### Common Issues
0 commit comments