Skip to content

Commit

Permalink
👌 Simplify AnalyticsTracker logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Jun 20, 2023
1 parent 14e2ce8 commit 43f81d9
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions Sources/AppcuesKit/Data/Analytics/AnalyticsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,20 @@ internal class AnalyticsTracker: AnalyticsTracking, AnalyticsSubscribing {
activityProcessor.process(activity) { [weak self] result in
switch result {
case .success(let qualifyResponse):
if !qualifyResponse.experiences.isEmpty {
if #available(iOS 13.0, *) {
let experienceRenderer = self?.container?.resolve(ExperienceRendering.self)
experienceRenderer?.processAndShow(
qualifiedExperiences: self?.process(qualifyResponse: qualifyResponse, activity: activity) ?? [],
reason: .qualification(reason: qualifyResponse.qualificationReason)
)
} else {
self?.config.logger.info("iOS 13 or above is required to render an Appcues experience")
// nothing will render, we can remove tracking
if #available(iOS 13.0, *) {
let experienceRenderer = self?.container?.resolve(ExperienceRendering.self)
experienceRenderer?.processAndShow(
qualifiedExperiences: self?.process(qualifyResponse: qualifyResponse, activity: activity) ?? [],
reason: .qualification(reason: qualifyResponse.qualificationReason)
)

if qualifyResponse.experiences.isEmpty {
// common case, nothing qualified - we know there was nothing to render, so just remove tracking
SdkMetrics.remove(activity.requestID)
}
} else {
if #available(iOS 13.0, *) {
let experienceRenderer = self?.container?.resolve(ExperienceRendering.self)
experienceRenderer?.processAndShow(
qualifiedExperiences: [],
reason: .qualification(reason: qualifyResponse.qualificationReason)
)
}

// common case, nothing qualified - we know there was nothing to render, so just remove tracking
self?.config.logger.info("iOS 13 or above is required to render an Appcues experience")
// nothing will render, we can remove tracking
SdkMetrics.remove(activity.requestID)
}
case .failure(let error):
Expand Down

0 comments on commit 43f81d9

Please sign in to comment.