نقل البيانات إلى Config API

يقدّم هذا الدليل أمثلة على نقل البيانات من طرق الإعداد القديمة إلى مكتبة "علامة ناشر Google" ‏ (GPT) الجديدة setConfig و getConfig واجهات برمجة التطبيقات.

توفّر واجهتا برمجة التطبيقات setConfig وgetConfig طريقة مركزية لإدارة الإعدادات على مستوى الصفحة والخانة.

ضبط الإعدادات على مستوى الصفحة

يوضّح الجدول التالي طرق إعداد PubAdsService القديمة وبدائلها في setConfig.

الميزة الطريقة القديمة استبدال "setConfig"
سمات AdSense set(key, value) googletag.setConfig({ adsenseAttributes: { [key]: value } })
استبعاد الفئات clearCategoryExclusions() googletag.setConfig({ categoryExclusion: null })
setCategoryExclusion(label) googletag.setConfig({ categoryExclusion: [label] })
التوسيط setCentering(centerAds) googletag.setConfig({ centering: centerAds })
تصغير عناصر div الفارغة collapseEmptyDivs(collapseBeforeFetch) googletag.setConfig({ collapseDiv: collapseBeforeFetch ? 'BEFORE_FETCH' : 'ON_NO_FILL' })
التحميل الأولي وبنية الإعلان الأحادي الطلب (SRA) disableInitialLoad() googletag.setConfig({ disableInitialLoad: true })
enableSingleRequest() googletag.setConfig({ singleRequest: true })
التحميل الكسول enableLazyLoad(config) googletag.setConfig({ lazyLoad: config })
الموقع الجغرافي setLocation(address) googletag.setConfig({ location: address })
SafeFrame setForceSafeFrame(force) googletag.setConfig({ safeFrame: { forceSafeFrame: force } })
setSafeFrameConfig(config) googletag.setConfig({ safeFrame: config })
الاستهداف clearTargeting(key) googletag.setConfig({ targeting: { [key]: null } })
setTargeting(key, value) googletag.setConfig({ targeting: { [key]: value } })
إعلانات الفيديو enableVideoAds() googletag.setConfig({ videoAds: { enableVideoAds: true } })
setVideoContent(contentId, cmsId) googletag.setConfig({ videoAds: { enableVideoAds: true, videoContentId: contentId, videoCmsId: cmsId } })

سمات AdSense

Legacy:

googletag.pubads().set('document_language', 'en');

الجديد:

googletag.setConfig({
  adsenseAttributes: {
    document_language: 'en'
  }
});

استبعاد الفئات

Legacy:

googletag.pubads().setCategoryExclusion('AirlineAd');
googletag.pubads().clearCategoryExclusions();

الجديد:

// Set category exclusion
googletag.setConfig({
  categoryExclusion: ['AirlineAd']
});

// Clear category exclusions
googletag.setConfig({
  categoryExclusion: null
});

توسيط

Legacy:

googletag.pubads().setCentering(true);

الجديد:

googletag.setConfig({
  centering: true
});

تصغير عناصر div الفارغة

Legacy:

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)

Legacy:

googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();

الجديد:

googletag.setConfig({
  disableInitialLoad: true,
  singleRequest: true
});

التحميل الكسول

Legacy:

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,
  },
});

الموقع الجغرافي

Legacy:

googletag.pubads().setLocation('10001,US');

الجديد:

googletag.setConfig({
  location: '10001,US'
});

SafeFrame

Legacy:

googletag.pubads().setForceSafeFrame(true);
googletag.pubads().setSafeFrameConfig({sandbox: true});

الجديد:

googletag.setConfig({
  safeFrame: {
    forceSafeFrame: true,
    sandbox: true
  }
});

الاستهداف

Legacy:

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
});

إعلانات الفيديو

Legacy:

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

Legacy:

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'
  }
});

استبعاد الفئات

Legacy:

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

Legacy:

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 الفارغة

Legacy:

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

Legacy:

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
  }
});

الاستهداف

Legacy:

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.

الميزة الطريقة القديمة استبدال "getConfig"
سمات AdSense get(key) googletag.getConfig('adsenseAttributes')
getAttributeKeys() googletag.getConfig('adsenseAttributes')
التحميل الأوّلي isInitialLoadDisabled() googletag.getConfig('disableInitialLoad')
الاستهداف getTargeting(key) googletag.getConfig('targeting')
getTargetingKeys() googletag.getConfig('targeting')

سمات AdSense

Legacy:

const documentLanguage = 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);

التحميل الأوّلي

Legacy:

const isDisabled = googletag.pubads().isInitialLoadDisabled();

الجديد:

const isDisabled = googletag.getConfig('disableInitialLoad').disableInitialLoad;

الاستهداف

Legacy:

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.

الميزة الطريقة القديمة استبدال "getConfig"
سمات AdSense get(key) Slot.getConfig('adsenseAttributes')
getAttributeKeys() Slot.getConfig('adsenseAttributes')
استبعاد الفئات getCategoryExclusions() Slot.getConfig('categoryExclusion')
الاستهداف getTargeting(key) Slot.getConfig('targeting')
getTargetingKeys() Slot.getConfig('targeting')

سمات AdSense

Legacy:

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 keys.
const adsenseAttributes = Object.keys(adsenseConfig);

استبعاد الفئات

Legacy:

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 || [];

الاستهداف

Legacy:

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);