Skip to content

Commit

Permalink
Fixed experiment pixel metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nalcalag committed Feb 26, 2025
1 parent ab08821 commit 1a9b61e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ interface FreeTrialExperimentDataStore {
* Returns the number [Int] of paywall impressions for the given [definition]
*/
suspend fun getMetricForPixelDefinition(definition: PixelDefinition): Int

/**
* Increases the count of paywall impressions for the given [definition]
*/
suspend fun increaseMetricForPixelDefinition(definition: PixelDefinition): Int
}

@ContributesBinding(AppScope::class)
Expand Down Expand Up @@ -68,6 +73,17 @@ class FreeTrialExperimentDataStoreImpl @Inject constructor(
}
}

override suspend fun increaseMetricForPixelDefinition(definition: PixelDefinition): Int =
withContext(dispatcherProvider.io()) {
val tag = "$definition"
val count = preferences.getInt(tag, 0)
preferences.edit {
putInt(tag, count + 1)
apply()
}
preferences.getInt(tag, 0)
}

companion object {
private const val FILENAME = "com.duckduckgo.subscriptions.freetrial.store"
private const val KEY_PAYWALL_IMPRESSIONS = "PAYWALL_IMPRESSIONS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ class FreeTrialPrivacyProPixelsPlugin @Inject constructor(
metricsPixel?.let { metric ->
metric.getPixelDefinitions().forEach { definition ->
if (definition.isInConversionWindow()) {
freeTrialExperimentDataStore.getMetricForPixelDefinition(definition).takeIf { it < metric.value.toInt() }?.let {
freeTrialExperimentDataStore.getMetricForPixelDefinition(definition).takeIf {
it < freeTrialExperimentDataStore.paywallImpressions
}?.let {
freeTrialExperimentDataStore.increaseMetricForPixelDefinition(definition)
pixel.fire(definition.pixelName, definition.params)
}
}
Expand Down

0 comments on commit 1a9b61e

Please sign in to comment.