Skip to content

Commit 4ca516d

Browse files
committed
Add schema for experiment metrics and validate it in tests.
1 parent ddee60b commit 4ca516d

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

pixel-definitions/pixels/experiments.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,48 @@
2626
"format": "date"
2727
}
2828
]
29+
},
30+
"experiment.metrics": {
31+
"description": "Triggered when user converted on a given metric in the scope of an A/B/N experiment.",
32+
"owners": [
33+
"smacbeth"
34+
],
35+
"triggers": [
36+
"startup",
37+
"user_submitted",
38+
"search_ddg"
39+
],
40+
"suffixes": [
41+
{
42+
"description": "Experiment user is being enrolled in: equal to the sub feature name",
43+
"type": "string"
44+
},
45+
{
46+
"description": "Cohort the user has chosen",
47+
"type": "string"
48+
},
49+
"extension",
50+
"browser"
51+
],
52+
"parameters": [
53+
{
54+
"key": "enrollmentDate",
55+
"description": "Date the enrollment happened.",
56+
"format": "date"
57+
},
58+
{
59+
"key": "metric",
60+
"description": "Name of the metric triggered (e.g. 'search')"
61+
},
62+
{
63+
"key": "conversionWindowDays",
64+
"description": "Conversion window the metric triggered in.",
65+
"pattern": "[0-9]+(-[0-9]+)?"
66+
},
67+
{
68+
"key": "value",
69+
"description": "Value associated with the metric, e.g. number of times it triggered within the period."
70+
}
71+
]
2972
}
3073
}

unit-test/background/abn-framework.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('choseCohort', () => {
161161
});
162162
});
163163

164-
fdescribe('ABN pixels', () => {
164+
describe('ABN pixels', () => {
165165
const feature = 'testFeature';
166166
const subFeature = 'fooFeature';
167167
const mockExperimentConfig = {
@@ -241,7 +241,7 @@ fdescribe('ABN pixels', () => {
241241
expect(pixelIntercept).toHaveBeenCalledTimes(2);
242242
expect(pixelRequests[1]).toContain('conversionWindowDays=0&');
243243
expect(pixelRequests[1]).toContain('value=1&');
244-
// TODO: pixel validation
244+
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[1])).toEqual([]);
245245
});
246246

247247
it('onMetricTriggered can trigger multiple matching metrics', () => {
@@ -258,6 +258,8 @@ fdescribe('ABN pixels', () => {
258258
.filter((u) => u.startsWith('/t/experiment_metrics_'))
259259
.map((u) => new URLSearchParams(u.split('?')[1]).get('conversionWindowDays'));
260260
expect(sentConversionWindows).toEqual(['6', '5-7']);
261+
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[1])).toEqual([]);
262+
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[2])).toEqual([]);
261263
});
262264

263265
it('metric conversion window is inclusive of first and last days', () => {
@@ -277,6 +279,11 @@ fdescribe('ABN pixels', () => {
277279
.filter((u) => u.startsWith('/t/experiment_metrics_'))
278280
.map((u) => new URLSearchParams(u.split('?')[1]).get('conversionWindowDays'));
279281
expect(sentConversionWindows).toEqual(['5', '5-7', '7', '5-7']);
282+
pixelRequests.forEach((u) => {
283+
if (u.startsWith('/t/experiment_metrics_')) {
284+
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', u)).toEqual([]);
285+
}
286+
})
280287
});
281288

282289
it('metric value count applies to conversion window only', () => {

0 commit comments

Comments
 (0)