From 50cbd18e849714b8b8ed60d5ca58fd4350183d1b Mon Sep 17 00:00:00 2001 From: Sabrina Tardio Date: Thu, 25 Jan 2024 09:33:00 +0100 Subject: [PATCH 1/4] revert experiment --- DuckDuckGo/Application/AppDelegate.swift | 5 +- .../Model/HomePageContinueSetUpModel.swift | 10 +- DuckDuckGo/HomePage/View/HomePageView.swift | 7 +- .../View/HomePageViewController.swift | 6 +- .../Model/DefaultBrowserPreferences.swift | 2 +- .../Statistics/ATB/StatisticsLoader.swift | 2 - .../Experiment/PixelExperiment.swift | 62 +--- DuckDuckGo/Statistics/PixelEvent.swift | 11 +- DuckDuckGo/Statistics/PixelParameters.swift | 22 +- .../YoutubeOverlayUserScript.swift | 2 +- .../PixelExperimentTests.swift | 305 +++++++++--------- 11 files changed, 179 insertions(+), 255 deletions(-) diff --git a/DuckDuckGo/Application/AppDelegate.swift b/DuckDuckGo/Application/AppDelegate.swift index 6812968476..50aeb37929 100644 --- a/DuckDuckGo/Application/AppDelegate.swift +++ b/DuckDuckGo/Application/AppDelegate.swift @@ -225,7 +225,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel if LocalStatisticsStore().atb == nil { Pixel.firstLaunchDate = Date() // MARK: Enable pixel experiments here - PixelExperiment.install() } AtbAndVariantCleanup.cleanup() DefaultVariantManager().assignVariantIfNeeded { _ in @@ -489,7 +488,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel private func emailDidSignInNotification(_ notification: Notification) { Pixel.fire(.emailEnabled) if Pixel.isNewUser { - PixelExperiment.fireEmailProtectionEnabledPixel() + Pixel.fire(.emailEnabledInitial, limitTo: .initial) } if let object = notification.object as? EmailManager, let emailManager = syncDataProviders.settingsAdapter.emailManager, object !== emailManager { @@ -506,7 +505,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel @objc private func dataImportCompleteNotification(_ notification: Notification) { if Pixel.isNewUser { - PixelExperiment.fireImportDataInitialPixel() + Pixel.fire(.importDataInitial, limitTo: .initial) } } diff --git a/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift b/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift index 5061faa4ba..94cbfc64e4 100644 --- a/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift +++ b/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift @@ -356,19 +356,16 @@ extension HomePage.Models { } private var shouldMakeDefaultCardBeVisible: Bool { - !PixelExperiment.isNoCardsExperimentOn && shouldShowMakeDefaultSetting && !defaultBrowserProvider.isDefault } private var shouldImportCardBeVisible: Bool { - !PixelExperiment.isNoCardsExperimentOn && shouldShowImportSetting && !dataImportProvider.didImport } private var shouldDuckPlayerCardBeVisible: Bool { - !PixelExperiment.isNoCardsExperimentOn && shouldShowDuckPlayerSetting && duckPlayerPreferences.duckPlayerModeBool == nil && !duckPlayerPreferences.youtubeOverlayAnyButtonPressed @@ -383,15 +380,13 @@ extension HomePage.Models { } private var shouldEmailProtectionCardBeVisible: Bool { - !PixelExperiment.isNoCardsExperimentOn && shouldShowEmailProtectionSetting && !emailManager.isSignedIn } private var shouldSurveyDay0BeVisible: Bool { let oneDayAgo = Calendar.current.date(byAdding: .weekday, value: -1, to: Date())! - return !PixelExperiment.isNoCardsExperimentOn && - isDay0SurveyEnabled && + return isDay0SurveyEnabled && shouldShowSurveyDay0 && !userInteractedWithSurveyDay0 && firstLaunchDate > oneDayAgo @@ -399,8 +394,7 @@ extension HomePage.Models { private var shouldSurveyDay7BeVisible: Bool { let oneWeekAgo = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: Date())! - return !PixelExperiment.isNoCardsExperimentOn && - isDay7SurveyEnabled && + return isDay7SurveyEnabled && shouldShowSurveyDay0 && shouldShowSurveyDay7 && !userInteractedWithSurveyDay0 && diff --git a/DuckDuckGo/HomePage/View/HomePageView.swift b/DuckDuckGo/HomePage/View/HomePageView.swift index 540982bc7f..2a0e5a7545 100644 --- a/DuckDuckGo/HomePage/View/HomePageView.swift +++ b/DuckDuckGo/HomePage/View/HomePageView.swift @@ -38,7 +38,7 @@ extension HomePage.Views { if isBurner { BurnerHomePageView() } else { - regularHomePageView(includingContinueSetUpCards: model.isContinueSetUpAvailable, isNoCardExperimentOn: PixelExperiment.isNoCardsExperimentOn) + regularHomePageView(includingContinueSetUpCards: model.isContinueSetUpAvailable) .contextMenu(ContextMenu(menuItems: { if model.isContinueSetUpAvailable { Toggle(UserText.newTabMenuItemShowContinuteSetUp, isOn: $model.isContinueSetUpVisible) @@ -53,15 +53,12 @@ extension HomePage.Views { } } - func regularHomePageView(includingContinueSetUpCards: Bool, isNoCardExperimentOn: Bool) -> some View { + func regularHomePageView(includingContinueSetUpCards: Bool) -> some View { ZStack(alignment: .top) { ScrollView { VStack(spacing: 0) { Group { - if isNoCardExperimentOn { - DefaultBrowserPrompt() - } if includingContinueSetUpCards { ContinueSetUpView() .padding(.top, 64) diff --git a/DuckDuckGo/HomePage/View/HomePageViewController.swift b/DuckDuckGo/HomePage/View/HomePageViewController.swift index 4210e5fb21..9033ef9d52 100644 --- a/DuckDuckGo/HomePage/View/HomePageViewController.swift +++ b/DuckDuckGo/HomePage/View/HomePageViewController.swift @@ -97,10 +97,8 @@ final class HomePageViewController: NSViewController { override func viewWillAppear() { super.viewWillAppear() - if !PixelExperiment.isExperimentInstalled { - if onboardingViewModel.onboardingFinished && Pixel.isNewUser { - Pixel.fire(.newTabInitial(), limitTo: .initial) - } + if onboardingViewModel.onboardingFinished && Pixel.isNewUser { + Pixel.fire(.newTabInitial, limitTo: .initial) } subscribeToHistory() } diff --git a/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift b/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift index 18d289d607..6d4c7492f2 100644 --- a/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift +++ b/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift @@ -78,7 +78,7 @@ final class DefaultBrowserPreferences: ObservableObject { guard NSApp.runType.requiresEnvironment else { return } #endif if Pixel.isNewUser && isDefault { - PixelExperiment.fireSetAsDefaultInitialPixel() + Pixel.fire(.setAsDefaultInitial, limitTo: .initial) } } } diff --git a/DuckDuckGo/Statistics/ATB/StatisticsLoader.swift b/DuckDuckGo/Statistics/ATB/StatisticsLoader.swift index de554c5c76..296f67e901 100644 --- a/DuckDuckGo/Statistics/ATB/StatisticsLoader.swift +++ b/DuckDuckGo/Statistics/ATB/StatisticsLoader.swift @@ -53,8 +53,6 @@ final class StatisticsLoader { completion() } } - PixelExperiment.fireFirstSerpPixel() - PixelExperiment.fireDay21To27SerpPixel() Pixel.fire(.serp) self.fireDailyOsVersionCounterPixel() } else if !self.statisticsStore.isAppRetentionFiredToday { diff --git a/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift b/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift index ecb305fa5b..0bccd0c940 100644 --- a/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift +++ b/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift @@ -32,15 +32,6 @@ enum PixelExperiment: String, CaseIterable { return logic.isInstalled } - static var isNoCardsExperimentOn: Bool { - // This is to avoid the cohort is assigned before the user actually sees the new tab page (after the onboarding has been completed) - if isExperimentInstalled && !OnboardingViewModel().onboardingFinished { - return true - } - // Cohort are assigned the first time it's called - return Self.cohort == .noCards - } - static var allocatedCohortDoesNotMatchCurrentCohorts: Bool { guard let allocatedCohort = logic.allocatedCohort else { return false } if PixelExperiment(rawValue: allocatedCohort) == nil { @@ -60,8 +51,7 @@ enum PixelExperiment: String, CaseIterable { // These are the variants. Rename or add/remove them as needed. If you change the string value // remember to keep it clear for privacy triage. - case control = "c" - case noCards = "d" + case control } /// These functions contain the business logic for determining if the pixel should be fired or not. @@ -79,21 +69,6 @@ extension PixelExperiment { logic.fireDay21To27SerpPixel() } - static func fireSetAsDefaultInitialPixel() { - logic.fireSetAsDefaultInitialPixel() - } - - static func fireImportDataInitialPixel() { - logic.fireImportDataInitialPixel() - } - - static func fireWatchInDuckPlayerPixel() { - logic.fireWatchInDuckPlayerPixel() - } - - static func fireEmailProtectionEnabledPixel() { - logic.fireEmailProtectionEnabledPixel() - } } @@ -158,14 +133,15 @@ final internal class PixelExperimentLogic { func fireEnrollmentPixel() { // You'll probably need this at least. guard allocatedCohort != nil, let cohort else { return } - Pixel.fire(.newTabInitial(cohort: cohort.rawValue), limitTo: .initial, includeAppVersionParameter: false) } + // Often used func fireFirstSerpPixel() { guard allocatedCohort != nil, let cohort else { return } Pixel.fire(.serpInitial(cohort: cohort.rawValue), limitTo: .initial, includeAppVersionParameter: false) } + // Often used for retention experiments func fireDay21To27SerpPixel() { guard allocatedCohort != nil, let cohort else { return } @@ -174,38 +150,6 @@ final internal class PixelExperimentLogic { } } - func fireSetAsDefaultInitialPixel() { - if allocatedCohort != nil, let cohort { - Pixel.fire(.setAsDefaultInitial(cohort: cohort.rawValue), limitTo: .initial) - } else { - Pixel.fire(.setAsDefaultInitial(), limitTo: .initial) - } - } - - func fireImportDataInitialPixel() { - if allocatedCohort != nil, let cohort { - Pixel.fire(.importDataInitial(cohort: cohort.rawValue), limitTo: .initial) - } else { - Pixel.fire(.importDataInitial(), limitTo: .initial) - } - } - - func fireWatchInDuckPlayerPixel() { - if allocatedCohort != nil, let cohort { - Pixel.fire(.watchInDuckPlayerInitial(cohort: cohort.rawValue), limitTo: .initial) - } else { - Pixel.fire(.watchInDuckPlayerInitial(), limitTo: .initial) - } - } - - func fireEmailProtectionEnabledPixel() { - if allocatedCohort != nil, let cohort { - Pixel.fire(.emailEnabledInitial(cohort: cohort.rawValue), limitTo: .initial) - } else { - Pixel.fire(.emailEnabledInitial(), limitTo: .initial) - } - } - func cleanup() { isInstalled = false allocatedCohort = nil diff --git a/DuckDuckGo/Statistics/PixelEvent.swift b/DuckDuckGo/Statistics/PixelEvent.swift index 2b9685b19b..e15e0c4066 100644 --- a/DuckDuckGo/Statistics/PixelEvent.swift +++ b/DuckDuckGo/Statistics/PixelEvent.swift @@ -131,12 +131,11 @@ extension Pixel { case debug(event: Debug, error: Error? = nil) // Activation Points - case newTabInitial(cohort: String? = nil) - case emailEnabledInitial(cohort: String? = nil) - - case watchInDuckPlayerInitial(cohort: String? = nil) - case setAsDefaultInitial(cohort: String? = nil) - case importDataInitial(cohort: String? = nil) + case newTabInitial + case emailEnabledInitial + case watchInDuckPlayerInitial + case setAsDefaultInitial + case importDataInitial // New Tab section removed case favoriteSectionHidden diff --git a/DuckDuckGo/Statistics/PixelParameters.swift b/DuckDuckGo/Statistics/PixelParameters.swift index 05b07f93e4..f5aa69b6c2 100644 --- a/DuckDuckGo/Statistics/PixelParameters.swift +++ b/DuckDuckGo/Statistics/PixelParameters.swift @@ -51,25 +51,12 @@ extension Pixel.Event { case .launchInitial(let cohort): return [PixelKit.Parameters.experimentCohort: cohort] + case .serpInitial(let cohort): return [PixelKit.Parameters.experimentCohort: cohort] + case .serpDay21to27(let cohort): return [PixelKit.Parameters.experimentCohort: cohort] - case .setAsDefaultInitial(let cohort): - guard let cohort else { return nil } - return [PixelKit.Parameters.experimentCohort: cohort] - case .newTabInitial(let cohort): - guard let cohort else { return nil } - return [PixelKit.Parameters.experimentCohort: cohort] - case .emailEnabledInitial(let cohort): - guard let cohort else { return nil } - return [PixelKit.Parameters.experimentCohort: cohort] - case .watchInDuckPlayerInitial(let cohort): - guard let cohort else { return nil } - return [PixelKit.Parameters.experimentCohort: cohort] - case .importDataInitial(let cohort): - guard let cohort else { return nil } - return [PixelKit.Parameters.experimentCohort: cohort] case .dailyPixel(let pixel, isFirst: _): return pixel.parameters @@ -118,6 +105,11 @@ extension Pixel.Event { .emailUserPressedUseAlias, .emailUserPressedUseAddress, .jsPixel, + .emailEnabledInitial, + .watchInDuckPlayerInitial, + .importDataInitial, + .newTabInitial, + .setAsDefaultInitial, .favoriteSectionHidden, .recentActivitySectionHidden, .continueSetUpSectionHidden, diff --git a/DuckDuckGo/YoutubePlayer/YoutubeOverlayUserScript.swift b/DuckDuckGo/YoutubePlayer/YoutubeOverlayUserScript.swift index d772ee884d..60906938bc 100644 --- a/DuckDuckGo/YoutubePlayer/YoutubeOverlayUserScript.swift +++ b/DuckDuckGo/YoutubePlayer/YoutubeOverlayUserScript.swift @@ -122,7 +122,7 @@ extension YoutubeOverlayUserScript { return nil } if pixelName == "play.use" { - PixelExperiment.fireWatchInDuckPlayerPixel() + Pixel.fire(.watchInDuckPlayerInitial, limitTo: .initial) } return nil } diff --git a/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift b/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift index e5ae9939a5..f35b1fd3ff 100644 --- a/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift +++ b/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift @@ -81,156 +81,159 @@ class PixelExperimentTests: XCTestCase { PixelExperiment.fireEnrollmentPixel() } - func testEnrollmentPixel() { - let e = expectation(description: "pixel fired") - Pixel.setUp(store: self.store) { [unowned self] event in - XCTAssertEqual(event, .newTabInitial(cohort: cohort!.rawValue)) - e.fulfill() - } - - Pixel.firstLaunchDate = now - PixelExperiment.install() - _=PixelExperiment.cohort - - PixelExperiment.fireEnrollmentPixel() - // only initial is set - PixelExperiment.fireEnrollmentPixel() - now = now.adding(.days(5)) - PixelExperiment.fireEnrollmentPixel() - - waitForExpectations(timeout: 0) - } - - func testFirstSerpPixel() { - let e = expectation(description: "enrollment pixel fired") - let e2 = expectation(description: "serp pixel fired") - Pixel.setUp(store: self.store) { [unowned self] event in - switch event { - case .newTabInitial(cohort: cohort.rawValue): - e.fulfill() - case .serpInitial(cohort: cohort.rawValue): - e2.fulfill() - default: - XCTFail("unexpected \(event)") - } - } - - Pixel.firstLaunchDate = now - PixelExperiment.install() - _=PixelExperiment.cohort - - PixelExperiment.fireFirstSerpPixel() - // only initial is set - PixelExperiment.fireFirstSerpPixel() - now = now.adding(.days(5)) - PixelExperiment.fireFirstSerpPixel() - - waitForExpectations(timeout: 0) - } - - func testDay21SerpPixel() { - let enrollment = expectation(description: "first pixel fired") - var e: XCTestExpectation! - Pixel.setUp(store: self.store) { [unowned self] event in - switch event { - case .newTabInitial(cohort: cohort.rawValue): - enrollment.fulfill() - case .serpDay21to27(cohort: cohort.rawValue): - e.fulfill() - default: - XCTFail("unexpected \(event)") - } - } - - let start = now - Pixel.firstLaunchDate = start - PixelExperiment.install() - _=PixelExperiment.cohort - - // only enrollment should fire - PixelExperiment.fireDay21To27SerpPixel() - waitForExpectations(timeout: 0) - - // shouldn‘t fire after 20 days - now = start.addingTimeInterval(.days(20)) - PixelExperiment.fireDay21To27SerpPixel() - - // should fire after 21 days - e = expectation(description: "21d pixel fired") - now = start.addingTimeInterval(.days(21)) - PixelExperiment.fireDay21To27SerpPixel() - waitForExpectations(timeout: 0) - - // shouldn‘t fire after 26 days (only initial) - now = start.addingTimeInterval(.days(26)) - PixelExperiment.fireDay21To27SerpPixel() - - // shouldn‘t fire after 27 days - now = start.addingTimeInterval(.days(27)) - PixelExperiment.fireDay21To27SerpPixel() - } - - func testDay27SerpPixel() { - let enrollment = expectation(description: "first pixel fired") - var e: XCTestExpectation! - Pixel.setUp(store: self.store) { [unowned self] event in - switch event { - case .newTabInitial(cohort: cohort.rawValue): - enrollment.fulfill() - case .serpDay21to27(cohort: cohort.rawValue): - e.fulfill() - default: - XCTFail("unexpected \(event)") - } - } - - let start = now - Pixel.firstLaunchDate = start - PixelExperiment.install() - _=PixelExperiment.cohort - - // only enrollment should fire - PixelExperiment.fireDay21To27SerpPixel() - waitForExpectations(timeout: 0) - - // shouldn‘t fire after 20 days - now = start.addingTimeInterval(.days(20)) - PixelExperiment.fireDay21To27SerpPixel() - - // should fire after 27 days - e = expectation(description: "27d pixel fired") - now = start.addingTimeInterval(.days(27)) - PixelExperiment.fireDay21To27SerpPixel() - waitForExpectations(timeout: 0) - - // shouldn‘t fire after 28 days - now = start.addingTimeInterval(.days(28)) - PixelExperiment.fireDay21To27SerpPixel() - } - - func testDay28SerpPixel() { - let enrollment = expectation(description: "first pixel fired") - Pixel.setUp(store: self.store) { [unowned self] event in - switch event { - case .newTabInitial(cohort: cohort.rawValue): - enrollment.fulfill() - default: - XCTFail("unexpected \(event)") - } - } - - let start = now - Pixel.firstLaunchDate = start - PixelExperiment.install() - _=PixelExperiment.cohort - - // only enrollment should fire - PixelExperiment.fireDay21To27SerpPixel() - waitForExpectations(timeout: 0) - - // shouldn‘t fire after 28 days - now = start.addingTimeInterval(.days(28)) - PixelExperiment.fireDay21To27SerpPixel() - } +// MARK: In a pixel experiment, enable this test and use the correct entollment pixel instead of yourEnrollmentPixel +// func testEnrollmentPixel() { +// let e = expectation(description: "pixel fired") +// Pixel.setUp(store: self.store) { [unowned self] event in +// XCTAssertEqual(event, .yourEnrollmentPixel(cohort: cohort!.rawValue)) +// e.fulfill() +// } +// +// Pixel.firstLaunchDate = now +// PixelExperiment.install() +// _=PixelExperiment.cohort +// +// PixelExperiment.fireEnrollmentPixel() +// // only initial is set +// PixelExperiment.fireEnrollmentPixel() +// now = now.adding(.days(5)) +// PixelExperiment.fireEnrollmentPixel() +// +// waitForExpectations(timeout: 0) +// } + +// MARK: In a pixel experiment, if used first serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel +// func testFirstSerpPixel() { +// let e = expectation(description: "enrollment pixel fired") +// let e2 = expectation(description: "serp pixel fired") +// Pixel.setUp(store: self.store) { [unowned self] event in +// switch event { +// case .yourEnrollmentPixel(cohort: cohort.rawValue): +// e.fulfill() +// case .serpInitial(cohort: cohort.rawValue): +// e2.fulfill() +// default: +// XCTFail("unexpected \(event)") +// } +// } +// +// Pixel.firstLaunchDate = now +// PixelExperiment.install() +// _=PixelExperiment.cohort +// +// PixelExperiment.fireFirstSerpPixel() +// // only initial is set +// PixelExperiment.fireFirstSerpPixel() +// now = now.adding(.days(5)) +// PixelExperiment.fireFirstSerpPixel() +// +// waitForExpectations(timeout: 0) +// } + +// MARK: In a pixel experiment, if used retention serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel +// func testDay21SerpPixel() { +// let enrollment = expectation(description: "first pixel fired") +// var e: XCTestExpectation! +// Pixel.setUp(store: self.store) { [unowned self] event in +// switch event { +// case .yourEnrollmentPixel(cohort: cohort.rawValue): +// enrollment.fulfill() +// case .serpDay21to27(cohort: cohort.rawValue): +// e.fulfill() +// default: +// XCTFail("unexpected \(event)") +// } +// } +// +// let start = now +// Pixel.firstLaunchDate = start +// PixelExperiment.install() +// _=PixelExperiment.cohort +// +// // only enrollment should fire +// PixelExperiment.fireDay21To27SerpPixel() +// waitForExpectations(timeout: 0) +// +// // shouldn‘t fire after 20 days +// now = start.addingTimeInterval(.days(20)) +// PixelExperiment.fireDay21To27SerpPixel() +// +// // should fire after 21 days +// e = expectation(description: "21d pixel fired") +// now = start.addingTimeInterval(.days(21)) +// PixelExperiment.fireDay21To27SerpPixel() +// waitForExpectations(timeout: 0) +// +// // shouldn‘t fire after 26 days (only initial) +// now = start.addingTimeInterval(.days(26)) +// PixelExperiment.fireDay21To27SerpPixel() +// +// // shouldn‘t fire after 27 days +// now = start.addingTimeInterval(.days(27)) +// PixelExperiment.fireDay21To27SerpPixel() +// } + +// MARK: In a pixel experiment, if used retention serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel// func testDay27SerpPixel() { +// let enrollment = expectation(description: "first pixel fired") +// var e: XCTestExpectation! +// Pixel.setUp(store: self.store) { [unowned self] event in +// switch event { +// case .yourEnrollmentPixel(cohort: cohort.rawValue): +// enrollment.fulfill() +// case .serpDay21to27(cohort: cohort.rawValue): +// e.fulfill() +// default: +// XCTFail("unexpected \(event)") +// } +// } +// +// let start = now +// Pixel.firstLaunchDate = start +// PixelExperiment.install() +// _=PixelExperiment.cohort +// +// // only enrollment should fire +// PixelExperiment.fireDay21To27SerpPixel() +// waitForExpectations(timeout: 0) +// +// // shouldn‘t fire after 20 days +// now = start.addingTimeInterval(.days(20)) +// PixelExperiment.fireDay21To27SerpPixel() +// +// // should fire after 27 days +// e = expectation(description: "27d pixel fired") +// now = start.addingTimeInterval(.days(27)) +// PixelExperiment.fireDay21To27SerpPixel() +// waitForExpectations(timeout: 0) +// +// // shouldn‘t fire after 28 days +// now = start.addingTimeInterval(.days(28)) +// PixelExperiment.fireDay21To27SerpPixel() +// } + +// MARK: In a pixel experiment, if used retention serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel// func testDay28SerpPixel() { +// let enrollment = expectation(description: "first pixel fired") +// Pixel.setUp(store: self.store) { [unowned self] event in +// switch event { +// case .yourEnrollmentPixel(cohort: cohort.rawValue): +// enrollment.fulfill() +// default: +// XCTFail("unexpected \(event)") +// } +// } +// +// let start = now +// Pixel.firstLaunchDate = start +// PixelExperiment.install() +// _=PixelExperiment.cohort +// +// // only enrollment should fire +// PixelExperiment.fireDay21To27SerpPixel() +// waitForExpectations(timeout: 0) +// +// // shouldn‘t fire after 28 days +// now = start.addingTimeInterval(.days(28)) +// PixelExperiment.fireDay21To27SerpPixel() +// } } From f2b5fef8aeecdc05c518716dab2a5bd4a88de420 Mon Sep 17 00:00:00 2001 From: Sabrina Tardio Date: Thu, 25 Jan 2024 10:34:23 +0100 Subject: [PATCH 2/4] remove unwanted space --- DuckDuckGo/Statistics/Experiment/PixelExperiment.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift b/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift index 0bccd0c940..d907a2b43d 100644 --- a/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift +++ b/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift @@ -69,7 +69,6 @@ extension PixelExperiment { logic.fireDay21To27SerpPixel() } - } final internal class PixelExperimentLogic { From eb84e7e1d885d8519b064f486c9b19c0edb32834 Mon Sep 17 00:00:00 2001 From: Sabrina Tardio Date: Thu, 25 Jan 2024 10:52:07 +0100 Subject: [PATCH 3/4] remove unwanted line of code --- DuckDuckGo/Statistics/Experiment/PixelExperiment.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift b/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift index d907a2b43d..64af60e55b 100644 --- a/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift +++ b/DuckDuckGo/Statistics/Experiment/PixelExperiment.swift @@ -131,7 +131,6 @@ final internal class PixelExperimentLogic { // You'll need additional pixels for your experiment. Pass the cohort as a paramter. func fireEnrollmentPixel() { // You'll probably need this at least. - guard allocatedCohort != nil, let cohort else { return } } // Often used From 19a0c25566abf80914814f7887968343669429b6 Mon Sep 17 00:00:00 2001 From: Sabrina Tardio Date: Fri, 26 Jan 2024 13:05:40 +0100 Subject: [PATCH 4/4] remove commented out code --- .../PixelExperimentTests.swift | 156 +----------------- 1 file changed, 1 insertion(+), 155 deletions(-) diff --git a/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift b/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift index f35b1fd3ff..cb3953e760 100644 --- a/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift +++ b/UnitTests/Statistics/PixelExperiment/PixelExperimentTests.swift @@ -81,159 +81,5 @@ class PixelExperimentTests: XCTestCase { PixelExperiment.fireEnrollmentPixel() } -// MARK: In a pixel experiment, enable this test and use the correct entollment pixel instead of yourEnrollmentPixel -// func testEnrollmentPixel() { -// let e = expectation(description: "pixel fired") -// Pixel.setUp(store: self.store) { [unowned self] event in -// XCTAssertEqual(event, .yourEnrollmentPixel(cohort: cohort!.rawValue)) -// e.fulfill() -// } -// -// Pixel.firstLaunchDate = now -// PixelExperiment.install() -// _=PixelExperiment.cohort -// -// PixelExperiment.fireEnrollmentPixel() -// // only initial is set -// PixelExperiment.fireEnrollmentPixel() -// now = now.adding(.days(5)) -// PixelExperiment.fireEnrollmentPixel() -// -// waitForExpectations(timeout: 0) -// } - -// MARK: In a pixel experiment, if used first serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel -// func testFirstSerpPixel() { -// let e = expectation(description: "enrollment pixel fired") -// let e2 = expectation(description: "serp pixel fired") -// Pixel.setUp(store: self.store) { [unowned self] event in -// switch event { -// case .yourEnrollmentPixel(cohort: cohort.rawValue): -// e.fulfill() -// case .serpInitial(cohort: cohort.rawValue): -// e2.fulfill() -// default: -// XCTFail("unexpected \(event)") -// } -// } -// -// Pixel.firstLaunchDate = now -// PixelExperiment.install() -// _=PixelExperiment.cohort -// -// PixelExperiment.fireFirstSerpPixel() -// // only initial is set -// PixelExperiment.fireFirstSerpPixel() -// now = now.adding(.days(5)) -// PixelExperiment.fireFirstSerpPixel() -// -// waitForExpectations(timeout: 0) -// } - -// MARK: In a pixel experiment, if used retention serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel -// func testDay21SerpPixel() { -// let enrollment = expectation(description: "first pixel fired") -// var e: XCTestExpectation! -// Pixel.setUp(store: self.store) { [unowned self] event in -// switch event { -// case .yourEnrollmentPixel(cohort: cohort.rawValue): -// enrollment.fulfill() -// case .serpDay21to27(cohort: cohort.rawValue): -// e.fulfill() -// default: -// XCTFail("unexpected \(event)") -// } -// } -// -// let start = now -// Pixel.firstLaunchDate = start -// PixelExperiment.install() -// _=PixelExperiment.cohort -// -// // only enrollment should fire -// PixelExperiment.fireDay21To27SerpPixel() -// waitForExpectations(timeout: 0) -// -// // shouldn‘t fire after 20 days -// now = start.addingTimeInterval(.days(20)) -// PixelExperiment.fireDay21To27SerpPixel() -// -// // should fire after 21 days -// e = expectation(description: "21d pixel fired") -// now = start.addingTimeInterval(.days(21)) -// PixelExperiment.fireDay21To27SerpPixel() -// waitForExpectations(timeout: 0) -// -// // shouldn‘t fire after 26 days (only initial) -// now = start.addingTimeInterval(.days(26)) -// PixelExperiment.fireDay21To27SerpPixel() -// -// // shouldn‘t fire after 27 days -// now = start.addingTimeInterval(.days(27)) -// PixelExperiment.fireDay21To27SerpPixel() -// } - -// MARK: In a pixel experiment, if used retention serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel// func testDay27SerpPixel() { -// let enrollment = expectation(description: "first pixel fired") -// var e: XCTestExpectation! -// Pixel.setUp(store: self.store) { [unowned self] event in -// switch event { -// case .yourEnrollmentPixel(cohort: cohort.rawValue): -// enrollment.fulfill() -// case .serpDay21to27(cohort: cohort.rawValue): -// e.fulfill() -// default: -// XCTFail("unexpected \(event)") -// } -// } -// -// let start = now -// Pixel.firstLaunchDate = start -// PixelExperiment.install() -// _=PixelExperiment.cohort -// -// // only enrollment should fire -// PixelExperiment.fireDay21To27SerpPixel() -// waitForExpectations(timeout: 0) -// -// // shouldn‘t fire after 20 days -// now = start.addingTimeInterval(.days(20)) -// PixelExperiment.fireDay21To27SerpPixel() -// -// // should fire after 27 days -// e = expectation(description: "27d pixel fired") -// now = start.addingTimeInterval(.days(27)) -// PixelExperiment.fireDay21To27SerpPixel() -// waitForExpectations(timeout: 0) -// -// // shouldn‘t fire after 28 days -// now = start.addingTimeInterval(.days(28)) -// PixelExperiment.fireDay21To27SerpPixel() -// } - -// MARK: In a pixel experiment, if used retention serp pixel used, enable and use the correct entollment pixel instead of yourEnrollmentPixel// func testDay28SerpPixel() { -// let enrollment = expectation(description: "first pixel fired") -// Pixel.setUp(store: self.store) { [unowned self] event in -// switch event { -// case .yourEnrollmentPixel(cohort: cohort.rawValue): -// enrollment.fulfill() -// default: -// XCTFail("unexpected \(event)") -// } -// } -// -// let start = now -// Pixel.firstLaunchDate = start -// PixelExperiment.install() -// _=PixelExperiment.cohort -// -// // only enrollment should fire -// PixelExperiment.fireDay21To27SerpPixel() -// waitForExpectations(timeout: 0) -// -// // shouldn‘t fire after 28 days -// now = start.addingTimeInterval(.days(28)) -// PixelExperiment.fireDay21To27SerpPixel() -// } - + // See git history for fireFirstSerpPixel and fireDay21To27SerpPixel tests }