Skip to content

Commit

Permalink
Support deep extraction setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayterDev committed Dec 21, 2023
1 parent c971533 commit 6049341
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,15 @@ public final class AMPCanonicalExtractor: NSObject {

public func urlContainsAMPKeyword(_ url: URL?) -> Bool {
linkCleaner.lastAMPURLString = nil

let settings = TrackingLinkSettings(fromConfig: privacyConfig)

guard privacyConfig.isEnabled(featureKey: .ampLinks) else { return false }
guard settings.deepExtractionEnabled else { return false }
guard let url = url, !linkCleaner.isURLExcluded(url: url) else { return false }
let urlStr = url.absoluteString

let ampKeywords = TrackingLinkSettings(fromConfig: privacyConfig).ampKeywords
let ampKeywords = settings.ampKeywords

return ampKeywords.contains { keyword in
return urlStr.contains(keyword)
Expand Down Expand Up @@ -167,6 +171,10 @@ public final class AMPCanonicalExtractor: NSObject {
completion(nil)
return
}
guard TrackingLinkSettings(fromConfig: privacyConfig).deepExtractionEnabled else {
completion(nil)
return
}
guard let url = url, !linkCleaner.isURLExcluded(url: url) else {
completion(nil)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ struct TrackingLinkSettings {
let ampLinkFormats: [String]
let ampKeywords: [String]
let trackingParameters: [String]
let deepExtractionEnabled: Bool

struct Constants {
static let ampLinkFormats = "linkFormats"
static let ampKeywords = "keywords"
static let trackingParameters = "parameters"
static let deepExtractionEnabled = "deepExtractionEnabled"
}

init(fromConfig config: PrivacyConfiguration) {
Expand All @@ -36,6 +38,7 @@ struct TrackingLinkSettings {

ampLinkFormats = ampFeatureSettings[Constants.ampLinkFormats] as? [String] ?? []
ampKeywords = ampFeatureSettings[Constants.ampKeywords] as? [String] ?? []
deepExtractionEnabled = ampFeatureSettings[Constants.deepExtractionEnabled] as? Bool ?? false
trackingParameters = trackingParametersSettings[Constants.trackingParameters] as? [String] ?? []
}

Expand Down

0 comments on commit 6049341

Please sign in to comment.