Skip to content

Commit

Permalink
Add new survey parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed May 24, 2024
1 parent 03a8c13 commit efa97cc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
9 changes: 6 additions & 3 deletions DuckDuckGo/Common/Surveys/SurveyRemoteMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct SurveyRemoteMessage: Codable, Equatable, Identifiable, Hashable {

func presentableSurveyURL(
statisticsStore: StatisticsStore = LocalStatisticsStore(),
activationDateStore: WaitlistActivationDateStore = DefaultWaitlistActivationDateStore(source: .netP),
vpnActivationDateStore: WaitlistActivationDateStore = DefaultWaitlistActivationDateStore(source: .netP),
pirActivationDateStore: WaitlistActivationDateStore = DefaultWaitlistActivationDateStore(source: .dbp),
operatingSystemVersion: String = ProcessInfo.processInfo.operatingSystemVersion.description,
appVersion: String = AppVersion.shared.versionNumber,
hardwareModel: String? = HardwareModel.model
Expand All @@ -67,8 +68,10 @@ struct SurveyRemoteMessage: Codable, Equatable, Identifiable, Hashable {
operatingSystemVersion: operatingSystemVersion,
appVersion: appVersion,
hardwareModel: hardwareModel,
daysSinceActivation: activationDateStore.daysSinceActivation(),
daysSinceLastActive: activationDateStore.daysSinceLastActive()
daysSinceVPNActivated: vpnActivationDateStore.daysSinceActivation(),
daysSinceVPNLastActive: vpnActivationDateStore.daysSinceLastActive(),
daysSincePIRActivated: pirActivationDateStore.daysSinceActivation(),
daysSincePIRLastActive: pirActivationDateStore.daysSinceLastActive()
)

return surveyURLBuilder.buildSurveyURL(from: surveyURL)
Expand Down
49 changes: 33 additions & 16 deletions DuckDuckGo/Common/Surveys/SurveyURLBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,41 @@ final class SurveyURLBuilder {
enum SurveyURLParameters: String, CaseIterable {
case atb = "atb"
case atbVariant = "var"
case daysSinceActivated = "delta"
case macOSVersion = "mv"
case macOSVersion = "osv"
case appVersion = "ddgv"
case hardwareModel = "mo"
case lastDayActive = "da"

case vpnFirstUsed = "vpn_first_used"
case vpnLastUsed = "vpn_last_used"
case pirFirstUsed = "pir_first_used"
case pirLastUsed = "pir_last_used"
}

private let statisticsStore: StatisticsStore
private let operatingSystemVersion: String
private let appVersion: String
private let hardwareModel: String?
private let daysSinceActivation: Int?
private let daysSinceLastActive: Int?
private let daysSinceVPNActivated: Int?
private let daysSinceVPNLastActive: Int?
private let daysSincePIRActivated: Int?
private let daysSincePIRLastActive: Int?

init(statisticsStore: StatisticsStore,
operatingSystemVersion: String,
appVersion: String,
hardwareModel: String?,
daysSinceActivation: Int?,
daysSinceLastActive: Int?) {
daysSinceVPNActivated: Int?,
daysSinceVPNLastActive: Int?,
daysSincePIRActivated: Int?,
daysSincePIRLastActive: Int?) {
self.statisticsStore = statisticsStore
self.operatingSystemVersion = operatingSystemVersion
self.appVersion = appVersion
self.hardwareModel = hardwareModel
self.daysSinceActivation = daysSinceActivation
self.daysSinceLastActive = daysSinceLastActive
self.daysSinceVPNActivated = daysSinceVPNActivated
self.daysSinceVPNLastActive = daysSinceVPNLastActive
self.daysSincePIRActivated = daysSincePIRActivated
self.daysSincePIRLastActive = daysSincePIRLastActive
}

// swiftlint:disable:next cyclomatic_complexity
Expand All @@ -72,10 +81,6 @@ final class SurveyURLBuilder {
if let variant = statisticsStore.variant {
queryItems.append(queryItem(parameter: parameter, value: variant))
}
case .daysSinceActivated:
if let daysSinceActivation {
queryItems.append(queryItem(parameter: parameter, value: daysSinceActivation))
}
case .macOSVersion:
queryItems.append(queryItem(parameter: parameter, value: operatingSystemVersion))
case .appVersion:
Expand All @@ -84,9 +89,21 @@ final class SurveyURLBuilder {
if let hardwareModel = hardwareModel {
queryItems.append(queryItem(parameter: parameter, value: hardwareModel))
}
case .lastDayActive:
if let daysSinceLastActive {
queryItems.append(queryItem(parameter: parameter, value: daysSinceLastActive))
case .vpnFirstUsed:
if let daysSinceVPNActivated {
queryItems.append(queryItem(parameter: parameter, value: daysSinceVPNActivated))
}
case .vpnLastUsed:
if let daysSinceVPNLastActive {
queryItems.append(queryItem(parameter: parameter, value: daysSinceVPNLastActive))
}
case .pirFirstUsed:
if let daysSincePIRActivated {
queryItems.append(queryItem(parameter: parameter, value: daysSincePIRActivated))
}
case .pirLastUsed:
if let daysSincePIRLastActive {
queryItems.append(queryItem(parameter: parameter, value: daysSincePIRLastActive))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo/Preferences/Model/AutofillPreferencesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ final class AutofillPreferencesModel: ObservableObject {
operatingSystemVersion: operatingSystemVersion,
appVersion: appVersion,
hardwareModel: hardwareModel,
daysSinceActivation: activationDateStore.daysSinceActivation(),
daysSinceLastActive: activationDateStore.daysSinceLastActive()
daysSinceVPNActivated: nil,
daysSinceVPNLastActive: nil,
daysSincePIRActivated: nil,
daysSincePIRLastActive: nil
)

guard let surveyUrl = surveyURLBuilder.buildSurveyURLWithPasswordsCountSurveyParameter(from: "https://selfserve.decipherinc.com/survey/selfserve/32ab/240307") else {
Expand Down
9 changes: 6 additions & 3 deletions UnitTests/HomePage/SurveyRemoteMessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class SurveyRemoteMessageTests: XCTestCase {

let firstMessagePresentableSurveyURL = firstMessage.presentableSurveyURL(
statisticsStore: mockStatisticsStore,
activationDateStore: mockActivationDateStore,
vpnActivationDateStore: mockActivationDateStore,
operatingSystemVersion: "1.2.3",
appVersion: "4.5.6",
hardwareModel: "MacBookPro,123"
Expand Down Expand Up @@ -102,13 +102,16 @@ final class SurveyRemoteMessageTests: XCTestCase {

let presentableSurveyURL = message.presentableSurveyURL(
statisticsStore: mockStatisticsStore,
activationDateStore: mockActivationDateStore,
vpnActivationDateStore: mockActivationDateStore,
operatingSystemVersion: "1.2.3",
appVersion: "4.5.6",
hardwareModel: "MacBookPro,123"
)

let expectedURL = "https://duckduckgo.com/?atb=atb-123&var=variant&delta=2&mv=1.2.3&ddgv=4.5.6&mo=MacBookPro%252C123&da=1"
let expectedURL = """
https://duckduckgo.com/?atb=atb-123&var=variant&osv=1.2.3&ddgv=4.5.6&mo=MacBookPro%252C123&vpn_first_used=2&vpn_last_used=1
"""

XCTAssertEqual(presentableSurveyURL!.absoluteString, expectedURL)
}

Expand Down

0 comments on commit efa97cc

Please sign in to comment.