-
Notifications
You must be signed in to change notification settings - Fork 933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store full enrollment date on a/b/n and truncate before sending pixels #5535
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,12 @@ import com.duckduckgo.app.di.AppCoroutineScope | |
import com.duckduckgo.app.statistics.api.AtbLifecyclePlugin | ||
import com.duckduckgo.app.statistics.pixels.Pixel | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.feature.toggles.api.MetricsPixel | ||
import com.duckduckgo.feature.toggles.api.PixelDefinition | ||
import com.duckduckgo.feature.toggles.impl.MetricsPixelStore | ||
import com.duckduckgo.feature.toggles.impl.RetentionMetric.APP_USE | ||
import com.duckduckgo.feature.toggles.impl.RetentionMetric.SEARCH | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import java.time.LocalDate | ||
import java.time.ZoneId | ||
import java.time.ZonedDateTime | ||
import java.time.temporal.ChronoUnit | ||
|
@@ -46,7 +46,7 @@ class RetentionMetricsAtbLifecyclePlugin @Inject constructor( | |
appCoroutineScope.launch { | ||
searchMetricPixelsPlugin.getMetrics().forEach { metric -> | ||
metric.getPixelDefinitions().forEach { definition -> | ||
if (isInConversionWindow(definition)) { | ||
if (isInConversionWindow(definition, metric)) { | ||
store.getMetricForPixelDefinition(definition, SEARCH).takeIf { it < metric.value.toInt() }?.let { | ||
store.increaseMetricForPixelDefinition(definition, SEARCH).takeIf { it == metric.value.toInt() }?.apply { | ||
pixel.fire(definition.pixelName, definition.params) | ||
|
@@ -62,7 +62,7 @@ class RetentionMetricsAtbLifecyclePlugin @Inject constructor( | |
appCoroutineScope.launch { | ||
appUseMetricPixelsPlugin.getMetrics().forEach { metric -> | ||
metric.getPixelDefinitions().forEach { definition -> | ||
if (isInConversionWindow(definition)) { | ||
if (isInConversionWindow(definition, metric)) { | ||
store.getMetricForPixelDefinition(definition, APP_USE).takeIf { it < metric.value.toInt() }?.let { | ||
store.increaseMetricForPixelDefinition(definition, APP_USE).takeIf { it == metric.value.toInt() }?.apply { | ||
pixel.fire(definition.pixelName, definition.params) | ||
|
@@ -74,8 +74,8 @@ class RetentionMetricsAtbLifecyclePlugin @Inject constructor( | |
} | ||
} | ||
|
||
private fun isInConversionWindow(definition: PixelDefinition): Boolean { | ||
val enrollmentDate = definition.params["enrollmentDate"] ?: return false | ||
private fun isInConversionWindow(definition: PixelDefinition, metric: MetricsPixel): Boolean { | ||
val enrollmentDate = metric.toggle.getCohort()?.enrollmentDateET ?: return false | ||
val lowerWindow = definition.params["conversionWindowDays"]?.split("-")?.first()?.toInt() ?: return false | ||
val upperWindow = definition.params["conversionWindowDays"]?.split("-")?.last()?.toInt() ?: return false | ||
val daysDiff = daysBetweenTodayAnd(enrollmentDate) | ||
|
@@ -85,8 +85,7 @@ class RetentionMetricsAtbLifecyclePlugin @Inject constructor( | |
|
||
private fun daysBetweenTodayAnd(date: String): Long { | ||
val today = ZonedDateTime.now(ZoneId.of("America/New_York")) | ||
val localDate = LocalDate.parse(date) | ||
val zoneDateTime: ZonedDateTime = localDate.atStartOfDay(ZoneId.of("America/New_York")) | ||
return ChronoUnit.DAYS.between(zoneDateTime, today) | ||
val localDate = ZonedDateTime.parse(date) | ||
return ChronoUnit.DAYS.between(localDate, today) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now returns different values than it used to. Here's an example:
If the aim of the framework was only to check for calendar day changes without accounting for hours, then the new iteration would regress by being too precise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really need to be more precise, should be 24h diff rather than calendar days so the new one seems to work as expected compared to the old. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 In this case, #5535 (comment) would need to get updated in the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rolling back on this thought, it shouldn't be 24h so I'm changing this bit and leaving the other one as it is. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one more copy of this function in MetricsPixelInterceptor that we should also adjust, shouldn't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one looks fine to stay because it takes truncated days as parameter 👍 It would be great to add a small comment to the function parameter so that someone stumbling on this in the future will immediately understand the difference between the way we parse and use the variousNeeds to get updated in the end, refs #5535 (comment).enrollmentDate
instances.