מיגרציה של Config API

במדריך הזה מפורטות דוגמאות למעבר משיטות הגדרה מדור קודם לספרייה החדשה של Google Publisher Tag ‏ (GPT) setConfig ולממשקי ה-API getConfig.

ממשקי ה-API‏ 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) slot.setConfig({ safeFrame: { forceSafeFrame: force } })
setSafeFrameConfig(config) slot.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: { videoContentId: contentId, videoCmsId: cmsId } })

מאפייני 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] })
כתובת אתר לקליקים 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']
  }
})

אחזור של הגדרות ברמת הדף

בטבלה הבאה מפורט מיפוי של getter methods קודמים של PubAdsService ל-methods החדשים של 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);

אחזור הגדרה ברמת המשבצת

בטבלה הבאה מפורטות שיטות getter קודמות של 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);