Skip to content

Commit 3d4860b

Browse files
committed
Fix campaign wrongfully reported as intent when no link nor campaign
1 parent b6cc6fe commit 3d4860b

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

Sources/Traceback/Private/TracebackSDKImpl.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ final class TracebackSDKImpl {
111111
}
112112

113113
func getCampaignLink(from url: URL) async -> TracebackSDK.Result {
114+
115+
guard isTracebackURL(url) else {
116+
logger.info("The provided url is not a traceback url, ignoring")
117+
return .empty
118+
}
119+
114120
do {
115121
logger.info("Get campaign link")
116122

@@ -126,13 +132,22 @@ final class TracebackSDKImpl {
126132

127133
// 3. If no campaign, process locally
128134
guard let campaign else {
129-
logger.info("The link does not have a campaign, treat locally as intent")
130-
let deeplink = try? extractLink(from: url)
135+
logger.info("The link does not have a campaign, treat locally")
136+
137+
guard let deeplink = extractLink(from: url) else {
138+
logger.info("No deeplink found in the url, returning empty result")
139+
return .empty
140+
}
141+
142+
logger.info("Deeplink found in the url, returning intent result")
143+
logger.debug("Deeplink extracted from url: \(deeplink.absoluteString)")
131144

132145
return TracebackSDK.Result(
133146
url: deeplink,
134147
matchType: .intent,
135-
analytics: []
148+
analytics: [
149+
.campaignResolvedLocally(deeplink)
150+
]
136151
)
137152
}
138153

@@ -183,9 +198,9 @@ final class TracebackSDKImpl {
183198
/// defining the content is not allways plain visible in the url which opened the app, since we need to build
184199
/// a url that is valid for all platforms, and for installation path. This method extracts the real url to be
185200
/// opened.
186-
private func extractLink(from url: URL) throws -> URL? {
201+
private func extractLink(from url: URL) -> URL? {
187202
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
188-
throw TracebackError.ExtractLink.invalidURL
203+
return nil
189204
}
190205

191206
for queryItem in components.queryItems ?? [] {

Sources/Traceback/TracebackConfiguration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public enum TracebackAnalyticsEvent: Sendable {
1515
case postInstallError(Error)
1616
/// A get-campaign content url has been resolved
1717
case campaignResolved(URL)
18+
/// A get-campaign content url has been resolved locally
19+
case campaignResolvedLocally(URL)
1820
/// A get-campaign content url failure
1921
case campaignError(Error)
2022
}

Sources/Traceback/TracebackError.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ public enum NetworkError: Swift.Error, Equatable, Sendable {
1616

1717
/// Used to diagnose traceback's sdk errors
1818
enum TracebackError: Error {
19-
/// Indicates the url that triggered app opening is an invalid URL
20-
enum ExtractLink: Error {
21-
case invalidURL
22-
}
23-
/// Indicates an error from the URL that triggered app opening
24-
case extractLink(ExtractLink)
2519
/// Indicates a network error
2620
case network(NetworkError)
2721
/// Indicates an internal error, please refer to github issues

0 commit comments

Comments
 (0)