Skip to content

Commit

Permalink
Aligned Privacy dashboard first time pixel with Android
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Aug 2, 2024
1 parent 7f146c8 commit 6894299
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
4 changes: 3 additions & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,9 @@ extension MainViewController: OmniBarDelegate {
guard !isSERPPresented else { return }

// Track first tap of privacy icon button
contextualOnboardingPixelReporter.trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: isHighlighted)
if isHighlighted {
contextualOnboardingPixelReporter.trackPrivacyDashboardOpenedForFirstTime()
}
// Dismiss privacy icon animation when showing privacy dashboard
dismissPrivacyDashboardButtonPulse()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protocol OnboardingCustomInteractionPixelReporting {
func trackCustomSearch()
func trackCustomSite()
func trackSecondSiteVisit()
func trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: Bool)
func trackPrivacyDashboardOpenedForFirstTime()
}

protocol OnboardingScreenImpressionReporting {
Expand Down Expand Up @@ -96,12 +96,11 @@ final class OnboardingPixelReporter {
self.userDefaults = userDefaults
}

private func fire(event: Pixel.Event, unique: Bool, additionalParameters: [String: String] = [:]) {
let parameters: [Pixel.QueryParameters] = [.appVersion, .atb]
private func fire(event: Pixel.Event, unique: Bool, additionalParameters: [String: String] = [:], includedParameters: [Pixel.QueryParameters] = [.appVersion, .atb]) {
if unique {
uniquePixel.fire(pixel: event, withAdditionalParameters: additionalParameters, includedParameters: parameters)
uniquePixel.fire(pixel: event, withAdditionalParameters: additionalParameters, includedParameters: includedParameters)
} else {
pixel.fire(pixel: event, withAdditionalParameters: additionalParameters, includedParameters: parameters)
pixel.fire(pixel: event, withAdditionalParameters: additionalParameters, includedParameters: includedParameters)
}
}

Expand Down Expand Up @@ -163,13 +162,13 @@ extension OnboardingPixelReporter: OnboardingCustomInteractionPixelReporting {
}
}

func trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: Bool) {
func trackPrivacyDashboardOpenedForFirstTime() {
let daysSinceInstall = statisticsStore.installDate.flatMap { calendar.numberOfDaysBetween($0, and: dateProvider()) }
let additionalParameters = [
PixelParameters.fromOnboarding: String(fromOnboarding),
PixelParameters.fromOnboarding: "true",
PixelParameters.daysSinceInstall: String(daysSinceInstall ?? 0)
]
fire(event: .privacyDashboardFirstTimeOpenedUnique, unique: true, additionalParameters: additionalParameters)
fire(event: .privacyDashboardFirstTimeOpenedUnique, unique: true, additionalParameters: additionalParameters, includedParameters: [.appVersion])
}

}
Expand Down
10 changes: 3 additions & 7 deletions DuckDuckGoTests/OnboardingNavigationDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,28 @@ final class OnboardingNavigationDelegateTests: XCTestCase {

// MARK: Pixel

func testWhenPrivacyBarIconIsPressed_AndPrivacyIconIsHighlighted_ThenFireFirstTimePrivacyDashboardUsedPixel_AndFromOnboardingIsTrue() {
func testWhenPrivacyBarIconIsPressed_AndPrivacyIconIsHighlighted_ThenFireFirstTimePrivacyDashboardUsedPixel() {
// GIVEN
let isHighlighted = true
XCTAssertFalse(onboardingPixelReporter.didCallTrackPrivacyDashboardOpenedForFirstTime)
XCTAssertNil(onboardingPixelReporter.capturedFromOnboarding)

// WHEN
mainVC.onPrivacyIconPressed(isHighlighted: isHighlighted)

// THEN
XCTAssertTrue(onboardingPixelReporter.didCallTrackPrivacyDashboardOpenedForFirstTime)
XCTAssertEqual(onboardingPixelReporter.capturedFromOnboarding, true)
}

func testWhenPrivacyBarIconIsPressed_AndPrivacyIconIsNotHighlighted_ThenFireFirstTimePrivacyDashboardUsedPixel_AndFromOnboardingIsFalse() {
func testWhenPrivacyBarIconIsPressed_AndPrivacyIconIsNotHighlighted_ThenDoNotFireFirstTimePrivacyDashboardUsedPixel() {
// GIVEN
let isHighlighted = false
XCTAssertFalse(onboardingPixelReporter.didCallTrackPrivacyDashboardOpenedForFirstTime)
XCTAssertNil(onboardingPixelReporter.capturedFromOnboarding)

// WHEN
mainVC.onPrivacyIconPressed(isHighlighted: isHighlighted)

// THEN
XCTAssertTrue(onboardingPixelReporter.didCallTrackPrivacyDashboardOpenedForFirstTime)
XCTAssertEqual(onboardingPixelReporter.capturedFromOnboarding, false)
XCTAssertFalse(onboardingPixelReporter.didCallTrackPrivacyDashboardOpenedForFirstTime)
}

}
Expand Down
4 changes: 1 addition & 3 deletions DuckDuckGoTests/OnboardingPixelReporterMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ final class OnboardingPixelReporterMock: OnboardingSiteSuggestionsPixelReporting
private(set) var didCallTrackScreenImpressionCalled = false
private(set) var capturedScreenImpression: Pixel.Event?
private(set) var didCallTrackPrivacyDashboardOpenedForFirstTime = false
private(set) var capturedFromOnboarding: Bool?

func trackSiteSuggetionOptionTapped() {
didCallTrackSiteOptionTapped = true
Expand All @@ -62,8 +61,7 @@ final class OnboardingPixelReporterMock: OnboardingSiteSuggestionsPixelReporting
capturedScreenImpression = event
}

func trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: Bool) {
func trackPrivacyDashboardOpenedForFirstTime() {
didCallTrackPrivacyDashboardOpenedForFirstTime = true
capturedFromOnboarding = fromOnboarding
}
}
21 changes: 5 additions & 16 deletions DuckDuckGoTests/OnboardingPixelReporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,37 +234,26 @@ final class OnboardingPixelReporterTests: XCTestCase {
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedIncludeParameters, [])

// WHEN
sut.trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: true)
sut.trackPrivacyDashboardOpenedForFirstTime()

// THEN
XCTAssertTrue(OnboardingUniquePixelFireMock.didCallFire)
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedPixelEvent, expectedPixel)
XCTAssertEqual(expectedPixel.name, "m_privacy_dashboard_first_time_used_unique")
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedIncludeParameters, [.appVersion, .atb])
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedIncludeParameters, [.appVersion])
}

func testWhenTrackPrivacyDashboardOpenedForFirstTimeAndFromOnboardingFalseThenParameterIsSetToFalse() {
func testWhenTrackPrivacyDashboardOpenedForFirstTimeThenFromOnboardingParameterIsSetToTrue() {
// GIVEN
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedParams, [:])

// WHEN
sut.trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: true)
sut.trackPrivacyDashboardOpenedForFirstTime()

// THEN
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedParams["from_onboarding"], "true")
}

func testWhenTrackPrivacyDashboardOpenedForFirstTimeAndFromOnboardingTrueThenParameterIsSetToTrue() {
// GIVEN
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedParams, [:])

// WHEN
sut.trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: false)

// THEN
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedParams["from_onboarding"], "false")
}

func testWhenTrackPrivacyDashboardOpenedForFirstTimeThenDaysSinceInstallParameterIsSet() {
// GIVEN
let installDate = Date(timeIntervalSince1970: 1722348000) // 30th July 2024 GMT
Expand All @@ -273,7 +262,7 @@ final class OnboardingPixelReporterTests: XCTestCase {
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedParams, [:])

// WHEN
sut.trackPrivacyDashboardOpenedForFirstTime(fromOnboarding: false)
sut.trackPrivacyDashboardOpenedForFirstTime()

// THEN
XCTAssertEqual(OnboardingUniquePixelFireMock.capturedParams["daysSinceInstall"], "3")
Expand Down

0 comments on commit 6894299

Please sign in to comment.