-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Required**: Task/Issue URL: https://app.asana.com/0/1204186595873227/1208547600159201/f iOS PR: duckduckgo/iOS#3839 macOS PR: https://github.com/duckduckgo/macos-browser/pull/3755/files What kind of version bump will this require?: Major **Optional**: Tech Design URL: https://app.asana.com/0/1204186595873227/1209001242859416/f CC: **Description**: Adds pixel reporting for TDS override experiment
- Loading branch information
1 parent
12227e2
commit 4232acb
Showing
7 changed files
with
285 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Sources/PixelExperimentKit/TDSOverrideExperimentMetrics.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// TDSOverrideExperimentMetrics.swift | ||
// | ||
// Copyright © 2025 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import PixelKit | ||
import Configuration | ||
import BrowserServicesKit | ||
|
||
public enum TDSExperimentMetricType: String { | ||
/// Metric triggered when the privacy toggle is used. | ||
case privacyToggleUsed = "privacyToggleUsed" | ||
/// Metric triggered after 2 quick refreshes. | ||
case refresh2X = "2XRefresh" | ||
/// Metric triggered after 3 quick refreshes. | ||
case refresh3X = "3XRefresh" | ||
} | ||
|
||
public struct TDSOverrideExperimentMetrics { | ||
|
||
public typealias FirePixelExperiment = (SubfeatureID, String, ConversionWindow, String) -> Void | ||
public typealias FireDebugExperiment = (_ parameters: [String: String]) -> Void | ||
|
||
private struct ExperimentConfig { | ||
static var firePixelExperiment: FirePixelExperiment = { subfeatureID, metric, conversionWindow, value in | ||
PixelKit.fireExperimentPixel(for: subfeatureID, metric: metric, conversionWindowDays: conversionWindow, value: value) | ||
} | ||
} | ||
|
||
static func configureTDSOverrideExperimentMetrics(firePixelExperiment: @escaping FirePixelExperiment) { | ||
ExperimentConfig.firePixelExperiment = firePixelExperiment | ||
} | ||
|
||
public static var activeTDSExperimentNameWithCohort: String? { | ||
guard let featureFlagger = PixelKit.ExperimentConfig.featureFlagger else { return nil } | ||
|
||
return TDSExperimentType.allCases.compactMap { experimentType in | ||
guard let experimentData = featureFlagger.getAllActiveExperiments()[experimentType.subfeature.rawValue] else { return nil } | ||
return "\(experimentType.subfeature.rawValue)_\(experimentData.cohortID)" | ||
}.first | ||
} | ||
|
||
public static func fireTDSExperimentMetric( metricType: TDSExperimentMetricType, | ||
etag: String, | ||
fireDebugExperiment: @escaping FireDebugExperiment) { | ||
for experiment in TDSExperimentType.allCases { | ||
for day in 0...5 { | ||
ExperimentConfig.firePixelExperiment(experiment.subfeature.rawValue, | ||
metricType.rawValue, | ||
day...day, | ||
"1" | ||
) | ||
fireDebugBreakageExperiment(experimentType: experiment, | ||
etag: etag, | ||
fire: fireDebugExperiment | ||
) | ||
} | ||
} | ||
} | ||
|
||
private static func fireDebugBreakageExperiment(experimentType: TDSExperimentType, | ||
etag: String, | ||
fire: @escaping FireDebugExperiment) { | ||
guard | ||
let featureFlagger = PixelKit.ExperimentConfig.featureFlagger, | ||
let experimentData = featureFlagger.getAllActiveExperiments()[experimentType.subfeature.rawValue] | ||
else { return } | ||
|
||
let experimentName: String = experimentType.subfeature.rawValue + experimentData.cohortID | ||
let enrolmentDate = experimentData.enrollmentDate.toYYYYMMDDInET() | ||
let parameters = [ | ||
"experiment": experimentName, | ||
"enrolmentDate": enrolmentDate, | ||
"tdsEtag": etag | ||
] | ||
fire(parameters) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.