A/B टेस्टिंग चलाएं

A/B टेस्टिंग करने के लिए, Shared Storage वर्कलेट का इस्तेमाल करें.

Shared Storage API, Privacy Sandbox का एक प्रस्ताव है. इसका इस्तेमाल, अलग-अलग कामों के लिए और एक से ज़्यादा साइटों पर डेटा सेव करने के लिए किया जाता है. यह कई तरह के इस्तेमाल के उदाहरणों के साथ काम करता है. इसका एक उदाहरण A/B टेस्टिंग है. यह Chrome 104.0.5086.0 और उसके बाद के वर्शन में टेस्ट करने के लिए उपलब्ध है.

किसी उपयोगकर्ता को एक्सपेरिमेंट ग्रुप में असाइन किया जा सकता है. इसके बाद, उस ग्रुप को SharedStorage में सेव किया जा सकता है, ताकि उसे क्रॉस-साइट एनवायरमेंट में ऐक्सेस किया जा सके.

A/B टेस्टिंग का इस्तेमाल करना

Shared Storage के साथ A/B टेस्टिंग का इस्तेमाल करने के लिए, पक्का करें कि Chrome 104.0.5086.0 या उसके बाद के वर्शन का इस्तेमाल किया जा रहा हो. chrome://settings/adPrivacy में जाकर, विज्ञापन देखने वाले की निजता बनाए रखने से जुड़े सभी एपीआई चालू करें.

कमांड लाइन में --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames फ़्लैग का इस्तेमाल करके भी, शेयर किए गए स्टोरेज की सुविधा चालू की जा सकती है.

कोड सैंपल आज़माएँ

यह देखने के लिए कि किसी एक्सपेरिमेंट का असर आपकी उम्मीद के मुताबिक है या नहीं, कई साइटों पर A/B टेस्टिंग की जा सकती है. विज्ञापन देने वाले व्यक्ति या कंपनी या कॉन्टेंट बनाने वाले व्यक्ति या कंपनी के तौर पर, आपके पास यह चुनने का विकल्प होता है कि उपयोगकर्ता को किस ग्रुप में असाइन किया गया है. इसके आधार पर, अलग-अलग कॉन्टेंट या विज्ञापन दिखाए जा सकते हैं. ग्रुप असाइनमेंट को शेयर किए गए स्टोरेज में सेव किया जाता है. हालांकि, इसे बाहर नहीं निकाला जा सकता.

इस उदाहरण में:

  • ab-testing.js को एक फ़्रेम में एम्बेड किया जाना चाहिए. यह फ़्रेम, कंट्रोल और एक्सपेरिमेंट के दो कॉन्टेंट को मैप करता है. यह स्क्रिप्ट, एक्सपेरिमेंट के लिए Shared Storage के वर्कलेट को कॉल करती है.
  • ab-testing-worklet.js शेयर किया गया स्टोरेज वर्कलेट है. इससे यह पता चलता है कि उपयोगकर्ता को कौनसा ग्रुप असाइन किया गया है. इससे यह तय होता है कि कौनसा विज्ञापन दिखाया जाएगा.

ab-testing.js

// Randomly assigns a user to a group 0 or 1
function getExperimentGroup() {
  return Math.round(Math.random());
}

async function injectContent() {
  // Register the Shared Storage worklet
  await window.sharedStorage.worklet.addModule('ab-testing-worklet.js');

  // Assign user to a random group (0 or 1) and store it in Shared Storage
  window.sharedStorage.set('ab-testing-group', getExperimentGroup(), {
    ignoreIfPresent: true,
  });

  // Run the URL selection operation
  const fencedFrameConfig = await window.sharedStorage.selectURL(
    'ab-testing',
    [
      { url: `https://your-server.example/content/default-content.html` },
      { url: `https://your-server.example/content/experiment-content-a.html` }
    ],
    {
      resolveToConfig: true
    }
  );

  // Render the chosen URL into a fenced frame
  document.getElementById('content-slot').config = fencedFrameConfig;
}

injectContent();

ab-testing-worklet.js

class SelectURLOperation {
  async run(urls, data) {
    // Read the user's experiment group from Shared Storage
    const experimentGroup = await sharedStorage.get('ab-testing-group');

    // Return the corresponding URL (first or second item in the array)
    return urls.indexOf(experimentGroup);
  }
}

register('ab-testing', SelectURLOperation);

Use cases

All available use cases for Select URL API can be found in this section. We'll continue to add examples as we receive feedback and discover new test cases.

Engage and share feedback

Note that the Select URL API proposal is under active discussion and development and subject to change.

We're eager to hear your thoughts on the Select URL API.