diff --git a/Core/PixelEvent.swift b/Core/PixelEvent.swift index 5bf18b4751..89c0a787b4 100644 --- a/Core/PixelEvent.swift +++ b/Core/PixelEvent.swift @@ -723,6 +723,7 @@ extension Pixel { // MARK: Apple Ad Attribution case appleAdAttribution + case appleAdAttributionNotAttributed // MARK: Secure Vault case secureVaultL1KeyMigration @@ -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" diff --git a/DuckDuckGo/AdAttribution/AdAttributionPixelReporter.swift b/DuckDuckGo/AdAttribution/AdAttributionPixelReporter.swift index 7e39be258c..24811b6fd0 100644 --- a/DuckDuckGo/AdAttribution/AdAttributionPixelReporter.swift +++ b/DuckDuckGo/AdAttribution/AdAttributionPixelReporter.swift @@ -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() diff --git a/DuckDuckGoTests/AdAttributionPixelReporterTests.swift b/DuckDuckGoTests/AdAttributionPixelReporterTests.swift index eb21f4507b..1c6a2a6d7c 100644 --- a/DuckDuckGoTests/AdAttributionPixelReporterTests.swift +++ b/DuckDuckGoTests/AdAttributionPixelReporterTests.swift @@ -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) }