-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send enrollment pixel when cohort is assigned (#5139)
Task/Issue URL: https://app.asana.com/0/1125189844152671/1208490557030192/f ### Description This PR sends an enrollment pixel whenever a cohort is assigned ### Steps to test this PR See task
- Loading branch information
1 parent
e27e11d
commit af63a0f
Showing
12 changed files
with
232 additions
and
2 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
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
55 changes: 55 additions & 0 deletions
55
...gles-impl/src/main/java/com/duckduckgo/feature/toggles/impl/RealFeatureTogglesCallback.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,55 @@ | ||
/* | ||
* 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.feature.toggles.impl | ||
|
||
import com.duckduckgo.app.statistics.pixels.Pixel | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.feature.toggles.impl.FeatureTogglesPixelName.EXPERIMENT_ENROLLMENT | ||
import com.duckduckgo.feature.toggles.internal.api.FeatureTogglesCallback | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import java.time.ZonedDateTime | ||
import java.time.format.DateTimeFormatter | ||
import javax.inject.Inject | ||
import okio.ByteString.Companion.encode | ||
|
||
@ContributesBinding(AppScope::class) | ||
class RealFeatureTogglesCallback @Inject constructor( | ||
private val pixel: Pixel, | ||
) : FeatureTogglesCallback { | ||
override fun onCohortAssigned( | ||
experimentName: String, | ||
cohortName: String, | ||
enrollmentDate: String, | ||
) { | ||
val parsedDate = ZonedDateTime.parse(enrollmentDate).format(DateTimeFormatter.ISO_LOCAL_DATE) | ||
val params = mapOf("enrollmentDate" to parsedDate) | ||
val pixelName = getPixelName(experimentName, cohortName) | ||
val tag = "${pixelName}_$params".encode().md5().hex() | ||
pixel.fire(pixelName = pixelName, parameters = params, type = Pixel.PixelType.Unique(tag = tag)) | ||
} | ||
|
||
private fun getPixelName( | ||
experimentName: String, | ||
cohortName: String, | ||
): String { | ||
return "${EXPERIMENT_ENROLLMENT.pixelName}_${experimentName}_$cohortName" | ||
} | ||
} | ||
|
||
internal enum class FeatureTogglesPixelName(override val pixelName: String) : Pixel.PixelName { | ||
EXPERIMENT_ENROLLMENT("experiment_enroll"), | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...-impl/src/test/java/com/duckduckgo/feature/toggles/impl/RealFeatureTogglesCallbackTest.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,26 @@ | ||
package com.duckduckgo.feature.toggles.impl | ||
|
||
import com.duckduckgo.app.statistics.pixels.Pixel | ||
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Unique | ||
import okio.ByteString.Companion.encode | ||
import org.junit.Test | ||
import org.mockito.Mockito.mock | ||
import org.mockito.kotlin.verify | ||
|
||
class RealFeatureTogglesCallbackTest { | ||
private val pixel: Pixel = mock() | ||
private val callback = RealFeatureTogglesCallback(pixel) | ||
|
||
@Test | ||
fun `test pixel is sent with correct parameters`() { | ||
val pixelName = "experiment_enroll_experimentName_cohortName" | ||
val params = mapOf("enrollmentDate" to "2024-10-15") | ||
val tag = "${pixelName}_$params".encode().md5().hex() | ||
callback.onCohortAssigned( | ||
experimentName = "experimentName", | ||
cohortName = "cohortName", | ||
enrollmentDate = "2024-10-15T00:00-04:00[America/New_York]", | ||
) | ||
verify(pixel).fire(pixelName = pixelName, parameters = params, type = Unique(tag)) | ||
} | ||
} |
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 @@ | ||
/build |
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,36 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id 'java-library' | ||
id 'kotlin' | ||
} | ||
|
||
apply from: "$rootProject.projectDir/code-formatting.gradle" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
dependencies { | ||
|
||
} | ||
|
29 changes: 29 additions & 0 deletions
29
...l-api/src/main/java/com/duckduckgo/feature/toggles/internal/api/FeatureTogglesCallback.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,29 @@ | ||
/* | ||
* 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.feature.toggles.internal.api | ||
|
||
/** | ||
* This interface exists to facilitate the implementation of ToggleImpl which contains logic inside an api module. | ||
* This is an internal implementation to thread the need between toggles-api and toggles-impl and should NEVER | ||
* be used publicly. | ||
*/ | ||
interface FeatureTogglesCallback { | ||
|
||
/** | ||
* This method is called whenever a cohort is assigned to the FeatureToggle | ||
*/ | ||
fun onCohortAssigned(experimentName: String, cohortName: String, enrollmentDate: String) | ||
} |