File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
shared/js/background/components Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -143,9 +143,16 @@ export default class AbnExperimentMetrics {
143
143
}
144
144
145
145
/**
146
- *
146
+ * Triggered when a given metric is triggered.
147
+ *
148
+ * Checks all active, enrolled subfeature experiments to find matching metrics that should be
149
+ * sent for them. With those that match, their counter is incremented by `value`, and if they
150
+ * exceed the threshold, a pixel is sent.
151
+ *
152
+ * After incrementing counters and potentially sending pixels, the updated cohort state is
153
+ * written back to settings.
147
154
* @param {string } metric
148
- * @param {number } value
155
+ * @param {number } [ value]
149
156
* @param {number } [timestamp]
150
157
*/
151
158
async onMetricTriggered ( metric , value = 1 , timestamp ) {
@@ -159,6 +166,8 @@ export default class AbnExperimentMetrics {
159
166
}
160
167
const enrollmentDate = new Date ( cohort . enrolledAt ) . toISOString ( ) . slice ( 0 , 10 ) ;
161
168
const daysSinceEnrollment = Math . floor ( ( ( timestamp || Date . now ( ) ) - cohort . enrolledAt ) / ( 1000 * 60 * 60 * 24 ) ) ;
169
+ // Find metrics for this experiment that match at this point in time.
170
+ // i.e. we are within the conversion window, and haven't sent the pixel yet.
162
171
const matchingPixels = cohort . metrics . filter (
163
172
( m ) =>
164
173
m . metric === metric &&
You can’t perform that action at this time.
0 commit comments