-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pixels to blocklist experiments (#5202)
Task/Issue URL: https://app.asana.com/0/1125189844152671/1208618649788232/f ### Description Adds pixels for blocklist experiments as well as a new parameter to the breakage form ### Steps to test this PR - [x] Change remote config to URL `https://jsonblob.com/api/1298581151181299712` - [x] Install the app, finish the onboarding - [x] Filter by `pixel sent` - [x] Go to a website - [x] Refresh it two times - [x] A bunch of pixels like `experiment_metrics_tdsNextExperimentBaseline_treatment with params: {metric=2xRefresh, value=1, enrollmentDate=2024-10-28, conversionWindowDays=0} {}` should be sent. - [x] Refresh three times - [x] A bunch of pixels like `experiment_metrics_tdsNextExperimentBaseline_treatment with params: {metric=3xRefresh, value=1, enrollmentDate=2024-10-28, conversionWindowDays=0} {}` should be sent. - [x] Send a broken site report - [x] The epbf pixel should contain `blockListExperiment=tdsNextExperimentBaseline_treatment` - [x] In the broken site report, disable protections - [x] No pixel with the name `experiment_metrics_tdsNextExperimentBaseline_treatment` should be sent. - [x] Re-enable protections - [x] Go to the privacy dashboard, website not working and disable protections from there. - [x] No pixel with the name `experiment_metrics_tdsNextExperimentBaseline_treatment` should be sent. - [x] Re-enable protections - [x] Go to the privacy dashboard, disable protections from there - [x] A bunch of pixels like `experiment_metrics_tdsNextExperimentBaseline_treatment with params: {metric=privacyToggleUsed, value=1, enrollmentDate=2024-10-28, conversionWindowDays=0} {}` should be sent
- Loading branch information
1 parent
d056ad8
commit 725ff6d
Showing
22 changed files
with
862 additions
and
135 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
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
160 changes: 160 additions & 0 deletions
160
app/src/main/java/com/duckduckgo/app/trackerdetection/blocklist/BlockList.kt
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,160 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.duckduckgo.app.trackerdetection.blocklist | ||
|
||
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature | ||
import com.duckduckgo.app.di.AppCoroutineScope | ||
import com.duckduckgo.app.trackerdetection.api.TrackerDataDownloader | ||
import com.duckduckgo.app.trackerdetection.blocklist.BlockList.Companion.EXPERIMENT_PREFIX | ||
import com.duckduckgo.app.trackerdetection.blocklist.ExperimentTestAA.Cohorts.CONTROL | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.feature.toggles.api.ConversionWindow | ||
import com.duckduckgo.feature.toggles.api.FeatureTogglesInventory | ||
import com.duckduckgo.feature.toggles.api.MetricsPixel | ||
import com.duckduckgo.feature.toggles.api.MetricsPixelPlugin | ||
import com.duckduckgo.feature.toggles.api.Toggle | ||
import com.duckduckgo.feature.toggles.api.Toggle.State.CohortName | ||
import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
@ContributesRemoteFeature( | ||
scope = AppScope::class, | ||
featureName = "blockList", | ||
) | ||
interface BlockList { | ||
@Toggle.DefaultValue(false) | ||
fun self(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentBaseline(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentBaselineBackup(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentNov24(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentDec24(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentJan25(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentFeb25(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun tdsNextExperimentMar25(): Toggle | ||
|
||
enum class Cohorts(override val cohortName: String) : CohortName { | ||
CONTROL("control"), | ||
TREATMENT("treatment"), | ||
} | ||
|
||
companion object { | ||
const val EXPERIMENT_PREFIX = "tds" | ||
const val TREATMENT_URL = "treatmentUrl" | ||
const val CONTROL_URL = "controlUrl" | ||
const val NEXT_URL = "nextUrl" | ||
} | ||
} | ||
|
||
@ContributesMultibinding(AppScope::class) | ||
class BlockListPixelsPlugin @Inject constructor(private val inventory: FeatureTogglesInventory) : MetricsPixelPlugin { | ||
|
||
override suspend fun getMetrics(): List<MetricsPixel> { | ||
val activeToggle = inventory.activeTdsFlag() ?: return emptyList() | ||
|
||
return listOf( | ||
MetricsPixel( | ||
metric = "2xRefresh", | ||
value = "1", | ||
toggle = activeToggle, | ||
conversionWindow = (0..5).map { ConversionWindow(lowerWindow = 0, upperWindow = it) }, | ||
), | ||
MetricsPixel( | ||
metric = "3xRefresh", | ||
value = "1", | ||
toggle = activeToggle, | ||
conversionWindow = (0..5).map { ConversionWindow(lowerWindow = 0, upperWindow = it) }, | ||
), | ||
MetricsPixel( | ||
metric = "privacyToggleUsed", | ||
value = "1", | ||
toggle = activeToggle, | ||
conversionWindow = (0..5).map { ConversionWindow(lowerWindow = 0, upperWindow = it) }, | ||
), | ||
) | ||
} | ||
} | ||
|
||
@ContributesMultibinding(AppScope::class) | ||
class BlockListPrivacyConfigCallbackPlugin @Inject constructor( | ||
private val inventory: FeatureTogglesInventory, | ||
private val trackerDataDownloader: TrackerDataDownloader, | ||
@AppCoroutineScope private val coroutineScope: CoroutineScope, | ||
private val experimentAA: ExperimentTestAA, | ||
private val dispatcherProvider: DispatcherProvider, | ||
) : PrivacyConfigCallbackPlugin { | ||
override fun onPrivacyConfigDownloaded() { | ||
coroutineScope.launch(dispatcherProvider.io()) { | ||
experimentAA.experimentTestAA().isEnabled(CONTROL) | ||
inventory.activeTdsFlag()?.let { | ||
trackerDataDownloader.downloadTds() | ||
} | ||
} | ||
} | ||
} | ||
|
||
internal suspend fun BlockListPixelsPlugin.get2XRefresh(): MetricsPixel? { | ||
return this.getMetrics().firstOrNull { it.metric == "2xRefresh" } | ||
} | ||
|
||
suspend fun BlockListPixelsPlugin.get3XRefresh(): MetricsPixel? { | ||
return this.getMetrics().firstOrNull { it.metric == "3xRefresh" } | ||
} | ||
|
||
suspend fun BlockListPixelsPlugin.getPrivacyToggleUsed(): MetricsPixel? { | ||
return this.getMetrics().firstOrNull { it.metric == "privacyToggleUsed" } | ||
} | ||
|
||
suspend fun FeatureTogglesInventory.activeTdsFlag(): Toggle? { | ||
return this.getAllTogglesForParent("blockList").firstOrNull { | ||
it.featureName().name.startsWith(EXPERIMENT_PREFIX) && it.isEnabled() | ||
} | ||
} | ||
|
||
@ContributesRemoteFeature( | ||
scope = AppScope::class, | ||
featureName = "experimentTest", | ||
) | ||
interface ExperimentTestAA { | ||
@Toggle.DefaultValue(false) | ||
fun self(): Toggle | ||
|
||
@Toggle.DefaultValue(false) | ||
fun experimentTestAA(): Toggle | ||
|
||
enum class Cohorts(override val cohortName: String) : CohortName { | ||
CONTROL("control"), | ||
TREATMENT("treatment"), | ||
} | ||
} |
Oops, something went wrong.