From 7a90bb38da044a5160d08edc59b93d22e0d4806d Mon Sep 17 00:00:00 2001 From: Tara Ojo Date: Mon, 5 Aug 2024 16:04:36 +0100 Subject: [PATCH] Update example to use createWorklet over addModule We want to show more uses of the createWorklet method, this example is a straight swap from addModule to createWorklet. In other examples I'll remove the use of the iframe. --- sites/content-producer/url-selection/ab-testing.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sites/content-producer/url-selection/ab-testing.js b/sites/content-producer/url-selection/ab-testing.js index 576fbe7..bf54113 100644 --- a/sites/content-producer/url-selection/ab-testing.js +++ b/sites/content-producer/url-selection/ab-testing.js @@ -42,7 +42,9 @@ function getRandomExperiment() { async function injectAd() { // Load the worklet module - await window.sharedStorage.worklet.addModule('ab-testing-worklet.js'); + const abTestingWorklet = await window.sharedStorage.createWorklet( + 'ab-testing-worklet.js' + ); // Set the initial value in the storage to a random experiment group window.sharedStorage.set('ab-testing-group', getRandomExperiment(), { @@ -56,7 +58,7 @@ async function injectAd() { const resolveToConfig = typeof window.FencedFrameConfig !== 'undefined'; // Run the URL selection operation to select an ad based on the experiment group in shared storage - const selectedUrl = await window.sharedStorage.selectURL('ab-testing', urls, { + const selectedUrl = await abTestingWorklet.selectURL('ab-testing', urls, { data: groups, resolveToConfig, keepAlive: true, @@ -71,7 +73,7 @@ async function injectAd() { } // Run the reporting operation - await window.sharedStorage.run('experiment-group-reporting') + await abTestingWorklet.run('experiment-group-reporting') } injectAd();