Skip to content

Commit

Permalink
Release PR: Check for the negative attribution case (#3311)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1199333091098016/1208213972615180/f
Tech Design URL:
CC:

Description:

This PR updates the attribution checker to handle the false case.
  • Loading branch information
samsymons authored Sep 5, 2024
1 parent 8bd7fc5 commit dddd0e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ extension Pixel {

// MARK: Apple Ad Attribution
case appleAdAttribution
case appleAdAttributionNotAttributed

// MARK: Secure Vault
case secureVaultL1KeyMigration
Expand Down Expand Up @@ -1431,6 +1432,7 @@ extension Pixel.Event {

// MARK: - Apple Ad Attribution
case .appleAdAttribution: return "m_apple-ad-attribution"
case .appleAdAttributionNotAttributed: return "m_apple-ad-attribution_not-attributed"

// MARK: - User behavior
case .userBehaviorReloadTwiceWithin12Seconds: return "m_reload-twice-within-12-seconds"
Expand Down
22 changes: 11 additions & 11 deletions DuckDuckGo/AdAttribution/AdAttributionPixelReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ final actor AdAttributionPixelReporter {
}

if let (token, attributionData) = await self.attributionFetcher.fetch() {
if attributionData.attribution {
let parameters = self.pixelParametersForAttribution(attributionData, attributionToken: token)
do {
try await pixelFiring.fire(
pixel: .appleAdAttribution,
withAdditionalParameters: parameters,
includedParameters: [.appVersion, .atb]
)
} catch {
return false
}
let event: Pixel.Event = attributionData.attribution ? .appleAdAttribution : .appleAdAttributionNotAttributed
let parameters = attributionData.attribution ? self.pixelParametersForAttribution(attributionData, attributionToken: token) : [:]

do {
try await pixelFiring.fire(
pixel: event,
withAdditionalParameters: parameters,
includedParameters: [.appVersion, .atb]
)
} catch {
return false
}

await fetcherStorage.markAttributionReportSuccessful()
Expand Down
7 changes: 5 additions & 2 deletions DuckDuckGoTests/AdAttributionPixelReporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ final class AdAttributionPixelReporterTests: XCTestCase {
XCTAssertNil(pixelAttributes["ad_id"])
}

func testPixelNotFiredAndMarksReport_WhenAttributionFalse() async {
func testNotAttributedPixelFiredAndMarkedReported_WhenAttributionFalse() async throws {
let sut = createSUT()
attributionFetcher.fetchResponse = ("example", AdServicesAttributionResponse(attribution: false))

let result = await sut.reportAttributionIfNeeded()

XCTAssertNil(PixelFiringMock.lastPixel)
let pixelAttributes = try XCTUnwrap(PixelFiringMock.lastParams)

XCTAssertEqual(pixelAttributes, [:])
XCTAssertEqual(PixelFiringMock.lastPixel?.name, "m_apple-ad-attribution_not-attributed")
XCTAssertTrue(fetcherStorage.wasAttributionReportSuccessful)
XCTAssertTrue(result)
}
Expand Down

0 comments on commit dddd0e2

Please sign in to comment.