يقدّم هذا الدليل أمثلة على نقل البيانات من طرق الإعداد القديمة إلى مكتبة setConfig وواجهات برمجة التطبيقات getConfig الجديدة لـ "علامة ناشر Google" (GPT).
توفّر واجهتا برمجة التطبيقات setConfig وgetConfig طريقة مركزية لإدارة الإعدادات على مستوى الصفحة والموضع.
ضبط الإعدادات على مستوى الصفحة
يوضّح الجدول التالي طرق إعداد PubAdsService القديمة وبدائلها setConfig.
سمات AdSense
الأنظمة القديمة:
googletag.pubads().set('document_language', 'en');
جديد:
googletag.setConfig({
adsenseAttributes: {
document_language: 'en'
}
});
استبعاد الفئات
الأنظمة القديمة:
googletag.pubads().setCategoryExclusion('AirlineAd');
googletag.pubads().clearCategoryExclusions();
جديد:
// Set category exclusion
googletag.setConfig({
categoryExclusion: ['AirlineAd']
});
// Clear category exclusions
googletag.setConfig({
categoryExclusion: null
});
التوسيط
الأنظمة القديمة:
googletag.pubads().setCentering(true);
جديد:
googletag.setConfig({
centering: true
});
تصغير عناصر div الفارغة
الأنظمة القديمة:
googletag.pubads().collapseEmptyDivs(true); // Collapse before fetch
googletag.pubads().collapseEmptyDivs(false); // Collapse on no fill
جديد:
// Collapse before fetch
googletag.setConfig({
collapseDiv: 'BEFORE_FETCH'
});
// Collapse on no fill
googletag.setConfig({
collapseDiv: 'ON_NO_FILL'
});
// Don't collapse
googletag.setConfig({
collapseDiv: 'DISABLED'
});
التحميل الأولي وبنية الإعلان الأحادي الطلب (SRA)
الأنظمة القديمة:
googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();
جديد:
googletag.setConfig({
disableInitialLoad: true,
singleRequest: true
});
التحميل الكسول
الأنظمة القديمة:
googletag.pubads().enableLazyLoad({
// Fetch slots within 5 viewports.
fetchMarginPercent: 500,
// Render slots within 2 viewports.
renderMarginPercent: 200,
// Double the above values on mobile.
mobileScaling: 2.0,
});
جديد:
googletag.setConfig({
lazyLoad: {
// Fetch slots within 5 viewports.
fetchMarginPercent: 500,
// Render slots within 2 viewports.
renderMarginPercent: 200,
// Double the above values on mobile.
mobileScaling: 2.0,
},
});
الموقع الجغرافي
الأنظمة القديمة:
googletag.pubads().setLocation('10001,US');
جديد:
googletag.setConfig({
location: '10001,US'
});
SafeFrame
الأنظمة القديمة:
googletag.pubads().setForceSafeFrame(true);
googletag.pubads().setSafeFrameConfig({sandbox: true});
جديد:
googletag.pubads().setConfig({
safeFrame: {
forceSafeFrame: true,
sandbox: true
}
});
الاستهداف
الأنظمة القديمة:
googletag.pubads().setTargeting('interests', 'sports');
googletag.pubads().setTargeting('interests', ['sports', 'music']);
googletag.pubads().clearTargeting('interests');
googletag.pubads().clearTargeting();
جديد:
// Set targeting
googletag.setConfig({
targeting: {
interests: 'sports'
}
});
// Set multiple values
googletag.setConfig({
targeting: {
interests: ['sports', 'music']
}
});
// Clear a specific key
googletag.setConfig({
targeting: {
interests: null
}
});
// Clear all targeting
googletag.setConfig({
targeting: null
});
إعلانات الفيديو
الأنظمة القديمة:
googletag.pubads().enableVideoAds();
googletag.pubads().setVideoContent('video123', 'cms456');
جديد:
googletag.setConfig({
videoAds: {
enableVideoAds: true,
videoContentId: 'video123',
videoCmsId: 'cms456'
}
});
ضبط الإعدادات على مستوى موضع الإعلان
يوضّح الجدول التالي طرق إعداد Slot القديمة وبدائلها setConfig.
| الميزة | الطريقة القديمة | استبدال "setConfig" |
|---|---|---|
| سمات AdSense | set(key, value) |
Slot.setConfig({ adsenseAttributes: { [key]: value } })
|
| استبعاد الفئات | clearCategoryExclusions() |
Slot.setConfig({ categoryExclusion: null })
|
setCategoryExclusion(label) |
Slot.setConfig({ categoryExclusion: [label] })
|
|
| عنوان URL للنقر | setClickUrl(url) |
Slot.setConfig({ clickUrl: url })
|
| تصغير عناصر div الفارغة | setCollapseEmptyDiv(collapse, collapseBeforeFetch) |
Slot.setConfig({ collapseDiv: collapse ? (collapseBeforeFetch ? 'BEFORE_FETCH' : 'ON_NO_FILL') : 'DISABLED' })
|
| SafeFrame | setForceSafeFrame(force) |
Slot.setConfig({ safeFrame: { forceSafeFrame: force } })
|
setSafeFrameConfig(config) |
Slot.setConfig({ safeFrame: config })
|
|
| الاستهداف | clearTargeting(key) |
Slot.setConfig({ targeting: { [key]: null } })
|
setTargeting(key, value) |
Slot.setConfig({ targeting: { [key]: value } })
|
|
updateTargetingFromMap(config) |
Slot.setConfig({ targeting: config })
|
سمات AdSense
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.set('adsense_background_color', '#FFFFFF');
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
adsenseAttributes: {
adsense_background_color: '#FFFFFF'
}
});
استبعاد الفئات
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setCategoryExclusion('AirlineAd');
slot.clearCategoryExclusions();
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
// Set category exclusion
slot.setConfig({
categoryExclusion: ['AirlineAd']
});
// Clear category exclusions
slot.setConfig({
categoryExclusion: null
});
انقر على عنوان URL
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setClickUrl('http://www.example.com?original_click_url=');
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
clickUrl: 'http://www.example.com?original_click_url='
});
تصغير div فارغ
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setCollapseEmptyDiv(true, true); // Collapse before fetch
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
collapseDiv: 'BEFORE_FETCH'
});
SafeFrame
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setForceSafeFrame(true);
slot.setSafeFrameConfig({sandbox: true});
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
safeFrame: {
forceSafeFrame: true,
sandbox: true
}
});
الاستهداف
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setTargeting('allow_expandable', 'true');
slot.clearTargeting('allow_expandable');
slot.updateTargetingFromMap({
color: 'red',
interests: ['sports', 'music', 'movies']
});
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
// Set targeting
slot.setConfig({
targeting: {
allow_expandable: 'true'
}
});
// Clear targeting
slot.setConfig({
targeting: {
allow_expandable: null
}
});
// Update targeting (only specified KVs are set/modified).
slot.setConfig({
targeting: {
color: 'red',
interests: ['sports', 'music', 'movies']
}
})
الحصول على إعدادات على مستوى الصفحة
يوضّح الجدول التالي كيفية ربط طرق إرجاع القيمة القديمة PubAdsService بطرق إرجاع القيمة البديلة getConfig.
| الميزة | الطريقة القديمة | استبدال "setConfig" |
|---|---|---|
| سمات AdSense | get(key) |
googletag.getConfig('adsenseAttributes')
|
getAttributeKeys() |
googletag.getConfig('adsenseAttributes')
|
|
| التحميل الأوّلي | isInitialLoadDisabled() |
googletag.getConfig('disableInitialLoad')
|
| الاستهداف | getTargeting(key) |
googletag.getConfig('targeting')
|
getTargetingKeys() |
googletag.getConfig('targeting')
|
سمات AdSense
الأنظمة القديمة:
const documentLangauage = googletag.pubads().get('document_language');
const adsenseAttributes = googletag.pubads().getAttributeKeys();
جديد:
const adsenseConfig = googletag.getConfig('adsenseAttributes').adsenseAttributes;
// Get the value of a single AdSense attribute.
const documentLanguage = adsenseConfig.document_language || null;
// Get all configured AdSense attribute keys.
const adsenseAttributes = Object.keys(adsenseConfig);
التحميل الأوّلي
الأنظمة القديمة:
const isDisabled = googletag.pubads().isInitialLoadDisabled();
جديد:
const isDisabled = googletag.getConfig('disableInitialLoad').disableInitialLoad;
الاستهداف
الأنظمة القديمة:
const targeting = googletag.pubads().getTargeting('interests');
const keys = googletag.pubads().getTargetingKeys();
جديد:
const targetingConfig = googletag.getConfig('targeting').targeting;
// Get targeting for a specific key.
const targeting = targetingConfig.interests || [];
// Get all targeting keys.
const keys = Object.keys(targetingConfig);
الحصول على إعدادات على مستوى الموضع الإعلاني
يوضّح الجدول التالي كيفية ربط طرق إرجاع القيمة القديمة Slot بطرق إرجاع القيمة البديلة getConfig.
| الميزة | الطريقة القديمة | استبدال "setConfig" |
|---|---|---|
| سمات AdSense | get(key) |
Slot.getConfig('adsenseAttributes')
|
getAttributeKeys() |
Slot.getConfig('adsenseAttributes')
|
|
| استبعاد الفئات | getCategoryExclusions() |
Slot.getConfig('categoryExclusion')
|
| الاستهداف | getTargeting(key) |
Slot.getConfig('targeting')
|
getTargetingKeys() |
Slot.getConfig('targeting')
|
سمات AdSense
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const bgColor = slot.get('adsense_background_color');
const adsenseAttributes = slot.getAttributeKeys();
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const adsenseConfig = slot.getConfig('adsenseAttributes').adsenseAttributes;
// Get the value of a single AdSense attribute.
const bgColor = adsenseConfig.adsense_background_color || null;
// Get all configured AdSense attribute.
const adsenseAttributes = Object.keys(adsenseConfig);
استبعاد الفئات
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const exclusions = slot.getCategoryExclusions();
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const exclusions = slot.getConfig('categoryExclusion').categoryExclusion || [];
الاستهداف
الأنظمة القديمة:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const targeting = slot.getTargeting('allow_expandable');
const keys = slot.getTargetingKeys();
جديد:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const targetingConfig = slot.getConfig('targeting').targeting;
// Get targeting for a specific key.
const targeting = targetingConfig.allow_expandable || [];
// Get all targeting keys.
const keys = Object.keys(targetingConfig);