diff --git a/sites/content-producer/url-selection/ab-testing-worklet.js b/sites/content-producer/url-selection/ab-testing-worklet.js index 35985ff..c815bf6 100644 --- a/sites/content-producer/url-selection/ab-testing-worklet.js +++ b/sites/content-producer/url-selection/ab-testing-worklet.js @@ -30,5 +30,26 @@ class SelectURLOperation { } } +function getBucketForTestingGroup(testingGroup) { + switch (testingGroup) { + case 'control': + return 0; + case 'experiment-a': + return 1; + case 'experiment-b': + return 2; + } +} + +class ExperimentGroupReportingOperation { + async run() { + const experimentGroup = await sharedStorage.get('ab-testing-group'); + + const bucket = BigInt(getBucketForTestingGroup(experimentGroup)); + privateAggregation.contributeToHistogram({ bucket, value: 1 }); + } +} + // Register the operation as 'ab-testing' register('ab-testing', SelectURLOperation); +register('experiment-group-reporting', ExperimentGroupReportingOperation); diff --git a/sites/content-producer/url-selection/ab-testing.js b/sites/content-producer/url-selection/ab-testing.js index 0f0b113..8997937 100644 --- a/sites/content-producer/url-selection/ab-testing.js +++ b/sites/content-producer/url-selection/ab-testing.js @@ -59,6 +59,7 @@ async function injectAd() { const selectedUrl = await window.sharedStorage.selectURL('ab-testing', urls, { data: groups, resolveToConfig, + keepAlive: true, }); const adSlot = document.getElementById('ad-slot'); @@ -68,6 +69,9 @@ async function injectAd() { } else { adSlot.src = selectedUrl; } + + // Run the reporting operation + await window.sharedStorage.run('experiment-group-reporting') } injectAd();