מריצים worklet של Shared Storage כדי לבחור כתובת URL ולעבד אותה ב-fenced frame.
Shared Storage API הוא הצעה של ארגז החול לפרטיות לאחסון כללי בין אתרים, שתומך בהרבה תרחישי שימוש אפשריים. דוגמה אחת היא בקרת תדירות, שזמינה לבדיקה ב-Chrome Beta 104.0.5086.0 ומעלה.
מריצים סקריפט של Worklet כדי לבחור כתובת URL מתוך רשימה שסופקה, על סמך הנתונים המאוחסנים, ואז מעבדים את כתובת ה-URL הזו בתוך fenced frame. אפשר להשתמש בזה כדי לבחור מודעות חדשות או תוכן אחר כשמגיעים למגבלת התדירות.
בדיקת בחירת הקריאייטיב לפי תדירות
כדי לבדוק בחירת קריאייטיב לפי תדירות באמצעות Shared Storage ו-Fenced Frames, צריך לוודא שאתם משתמשים ב-Chrome 104.0.5086.0 ואילך. מפעילים את כל ממשקי ה-API לשמירה על פרטיות בפרסום בקטע chrome://settings/adPrivacy.
אפשר גם להפעיל את האחסון המשותף באמצעות הדגל --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames בשורת הפקודה.
התנסות בדוגמאות קוד
כדי לבחור וליצור כתובת URL אטומה, צריך לרשום מודול worklet לקריאת נתונים של אחסון משותף. המחלקת worklet מקבלת רשימה של עד שמונה כתובות URL ואז מחזירה את האינדקס של כתובת ה-URL שנבחרה.
כשהלקוח קורא ל-sharedStorage.selectURL(), ה-worklet מופעל ומחזיר כתובת URL אטומה לעיבוד ב-fenced frame.
נניח שאתם רוצים לבחור מודעה או תוכן אחרים להצגה על סמך התדירות שבה משתמש מסוים ראה אותם בעבר. אתם יכולים לספור כמה פעמים משתמש צפה בתוכן מסוים, ולאחסן את הערך הזה באחסון משותף. אחרי שהערך נשמר, הוא זמין לכם באחסון המשותף ממקורות שונים.
לאחר מכן, ה-worklet של האחסון המשותף קורא את הערכים באחסון המשותף ומגדיל את הערך של המונה בכל צפייה נוספת. אם המספר לא הגיע למגבלה שהוגדרה מראש, התוכן שרוצים להציג מוחזר (אינדקס 1). אחרת, כתובת ה-URL שמוגדרת כברירת מחדל מוחזרת (אינדקס 0).
בדוגמה הזו:
-
creative-selection-by-frequencyjsנטען דרך iframe של יוצר התוכן או המפרסם, והוא אחראי לטעינת ה-worklet של האחסון המשותף ולעיבוד המקור האָטום שמוחזר לתוך fenced frame. -
creative-selection-by-frequency-worklet.jsהוא worklet של אחסון משותף שקורא את ספירת התדירות כדי לקבוע איזו כתובת URL מוחזרת עבור תוכן או נכס קריאטיבי של מודעה.
creative-selection-by-frequency.js
// The first URL is the default content or ad to be rendered when the frequency limits reached.
const CONTENT_URLS = [
{ url: `https://${contentProducerUrl}/default-content.html` },
{ url: `https://${contentProducerUrl}/example-content.html` },
];
async function injectAd() {
// Load the worklet module.
await window.sharedStorage.worklet.addModule('creative-selection-by-frequency-worklet.js');
// Set the initial frequency count
window.sharedStorage.set('frequency-count', 0, {
ignoreIfPresent: true,
});
// Run the URL selection operation to choose an ad based on the frequency count in shared storage.
const fencedFrameConfig = await window.sharedStorage.selectURL('creative-selection-by-frequency', CONTENT_URLS, {
resolveToConfig: true
});
// Render the opaque URL into a fenced frame
document.getElementById('content-slot').config = fencedFrameConfig;
}
injectAd();
creative-selection-by-frequency-worklet.js
const FREQUENCY_LIMIT = 5;
class CreativeSelectionByFrequencyOperation {
async run(urls, data) {
// Read the current frequency limit in shared storage
const count = parseInt(await sharedStorage.get('frequency-count'));
// Check if the frequency limit has been reached.
if (count === FREQUENCY_LIMIT) {
console.log('Frequency limit has been reached, and the default content will be rendered.');
return 0;
}
// Set the new frequency count in shared storage
await sharedStorage.set('frequency-count', count + 1);
return 1;
}
}
// Register the operation as 'creative-selection-by-frequency'.
register('creative-selection-by-frequency', CreativeSelectionByFrequencyOperation);
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.
- Rotate ad creatives: Store data, such as creative ID and user interaction, to determine which creative users' see across different sites.
- Select ad creatives by frequency: Use view count data to determine which creative users' see across different sites.
- Run A/B testing: You can assign a user to an experiment group, then store that group in Shared Storage to be accessed cross-site.
- Customize experience for known customers: Share custom content and calls-to-action based on a user's registration status or other user states.
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.
- Proposal: Review the detailed proposal.
- Discussion: Join the ongoing discussion to ask questions and share your insights.