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' })
शुरुआती लोड और सिंगल रिक्वेस्ट आर्किटेक्चर (एसआरए) 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'
});

शुरू में लोड होने वाला साइज़ और सिंगल रिक्वेस्ट आर्किटेक्चर (एसआरए)

लेगसी:

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

पेज-लेवल का कॉन्फ़िगरेशन पाना

यहां दी गई टेबल में, लेगसी 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);