Skip to content

Commit

Permalink
Merge branch 'main' into sam/vpn-clean-up
Browse files Browse the repository at this point in the history
* main:
  Deprecate PixelKit daily pixel suffixes (#1060)
  Update C-S-S to 6.29.0 (#1062)
  Send pixel on sync secure storage read failure (#1058)
  • Loading branch information
samsymons committed Nov 6, 2024
2 parents bca4c1a + 14594b6 commit fdd840c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "48fee2508995d4ac02d18b3d55424adedcb4ce4f",
"version" : "6.28.0"
"revision" : "6cab7bdb584653a5dc007cc1ae827ec41c5a91bc",
"version" : "6.29.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let package = Package(
.package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.3.0"),
.package(url: "https://github.com/gumob/PunycodeSwift.git", exact: "3.0.0"),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "7.1.1"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.28.0"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.29.0"),
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
.package(url: "https://github.com/1024jp/GzipSwift.git", exact: "6.0.1")
Expand Down
9 changes: 8 additions & 1 deletion Sources/DDGSync/DDGSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ public class DDGSync: DDGSyncing {
}

public var account: SyncAccount? {
try? dependencies.secureStore.account()
do {
return try dependencies.secureStore.account()
} catch {
if let syncError = error as? SyncError {
dependencies.errorEvents.fire(syncError, error: syncError)
}
return nil
}
}

public var scheduler: Scheduling {
Expand Down
10 changes: 10 additions & 0 deletions Sources/DDGSync/SyncError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,14 @@ extension SyncError: CustomNSError {
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .failedToReadSecureStore(let status), .failedToWriteSecureStore(let status), .failedToRemoveSecureStore(let status):
let underlyingError = NSError(domain: "secError", code: Int(status))
return [NSUnderlyingErrorKey: underlyingError]
default:
return [:]
}
}

}
23 changes: 21 additions & 2 deletions Sources/PixelKit/PixelKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ public final class PixelKit {
/// Sent once per day. The last timestamp for this pixel is stored and compared to the current date. Pixels of this type will have `_d` appended to their name.
case daily

/// Sent once per day with a `_d` suffix, in addition to every time it is called with a `_c` suffix.
/// [Legacy] Sent once per day with a `_d` suffix, in addition to every time it is called with a `_c` suffix.
/// This means a pixel will get sent twice the first time it is called per-day, and subsequent calls that day will only send the `_c` variant.
/// This is useful in situations where pixels receive spikes in volume, as the daily pixel can be used to determine how many users are actually affected.
case legacyDailyAndCount

/// Sent once per day with a `_daily` suffix, in addition to every time it is called with a `_count` suffix.
/// This means a pixel will get sent twice the first time it is called per-day, and subsequent calls that day will only send the `_count` variant.
/// This is useful in situations where pixels receive spikes in volume, as the daily pixel can be used to determine how many users are actually affected.
case dailyAndCount

fileprivate var description: String {
Expand All @@ -58,6 +63,8 @@ public final class PixelKit {
"Legacy Daily"
case .daily:
"Daily"
case .legacyDailyAndCount:
"Legacy Daily and Count"
case .dailyAndCount:
"Daily and Count"
}
Expand Down Expand Up @@ -233,7 +240,7 @@ public final class PixelKit {
} else {
printDebugInfo(pixelName: pixelName + "_d", frequency: frequency, parameters: newParams, skipped: true)
}
case .dailyAndCount:
case .legacyDailyAndCount:
reportErrorIf(pixel: pixelName, endsWith: "_u")
reportErrorIf(pixel: pixelName, endsWith: "_d") // Because is added automatically
reportErrorIf(pixel: pixelName, endsWith: "_c") // Because is added automatically
Expand All @@ -245,6 +252,18 @@ public final class PixelKit {
}

fireRequestWrapper(pixelName + "_c", headers, newParams, allowedQueryReservedCharacters, true, frequency, onComplete)
case .dailyAndCount:
reportErrorIf(pixel: pixelName, endsWith: "_u")
reportErrorIf(pixel: pixelName, endsWith: "_daily") // Because is added automatically
reportErrorIf(pixel: pixelName, endsWith: "_count") // Because is added automatically
if !pixelHasBeenFiredToday(pixelName) {
fireRequestWrapper(pixelName + "_daily", headers, newParams, allowedQueryReservedCharacters, true, frequency, onComplete)
updatePixelLastFireDate(pixelName: pixelName)
} else {
printDebugInfo(pixelName: pixelName + "_daily", frequency: frequency, parameters: newParams, skipped: true)
}

fireRequestWrapper(pixelName + "_count", headers, newParams, allowedQueryReservedCharacters, true, frequency, onComplete)
}
}

Expand Down
9 changes: 6 additions & 3 deletions Sources/PixelKitTestingUtilities/XCTestCase+PixelKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public extension XCTestCase {
let knownExpectedParameters = knownExpectedParameters(for: event)
let callbackExecutedExpectation = expectation(description: "The PixelKit callback has been executed")

if frequency == .dailyAndCount {
if frequency == .legacyDailyAndCount {
callbackExecutedExpectation.expectedFulfillmentCount = 2
}

Expand All @@ -123,7 +123,7 @@ public extension XCTestCase {
firedParameters[key] == value
}, file: file, line: line)

if frequency == .dailyAndCount {
if frequency == .legacyDailyAndCount {
XCTAssertTrue(firedPixelName.hasPrefix(expectations.pixelName))
XCTAssertTrue(firedPixelName.hasSuffix("_c") || firedPixelName.hasSuffix("_d"))
XCTAssertEqual(firedPixelName.count, expectations.pixelName.count + 2)
Expand Down Expand Up @@ -155,9 +155,12 @@ public extension XCTestCase {
expectedPixelNames.append(originalName)
case .daily:
expectedPixelNames.append(originalName.appending("_d"))
case .dailyAndCount:
case .legacyDailyAndCount:
expectedPixelNames.append(originalName.appending("_d"))
expectedPixelNames.append(originalName.appending("_c"))
case .dailyAndCount:
expectedPixelNames.append(originalName.appending("_daily"))
expectedPixelNames.append(originalName.appending("_count"))
}
return expectedPixelNames
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/PixelKitTests/PixelKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class PixelKitTests: XCTestCase {
case .dailyEvent, .dailyEventWithoutParameters:
return .daily
case .dailyAndContinuousEvent, .dailyAndContinuousEventWithoutParameters:
return .dailyAndCount
return .legacyDailyAndCount
}
}
}
Expand Down

0 comments on commit fdd840c

Please sign in to comment.