Bu kılavuzda, eski yapılandırma yöntemlerinden yeni Google Yayıncı Etiketi (GPT) kitaplığı setConfig ve getConfig API'lerine geçişle ilgili örnekler verilmektedir.
setConfig ve getConfig API'leri, hem sayfa hem de yuva düzeyindeki yapılandırmayı yönetmek için merkezi bir yol sağlar.
Sayfa düzeyinde yapılandırmayı ayarlama
Aşağıdaki tabloda, eski PubAdsService yapılandırma yöntemleri setConfig ile değiştirilen yöntemlerle eşlenmektedir.
AdSense özellikleri
Eski:
googletag.pubads().set('document_language', 'en');
Yeni:
googletag.setConfig({
adsenseAttributes: {
document_language: 'en'
}
});
Kategori hariç tutma
Eski:
googletag.pubads().setCategoryExclusion('AirlineAd');
googletag.pubads().clearCategoryExclusions();
Yeni:
// Set category exclusion
googletag.setConfig({
categoryExclusion: ['AirlineAd']
});
// Clear category exclusions
googletag.setConfig({
categoryExclusion: null
});
Ortalama
Eski:
googletag.pubads().setCentering(true);
Yeni:
googletag.setConfig({
centering: true
});
Boş div'leri daraltma
Eski:
googletag.pubads().collapseEmptyDivs(true); // Collapse before fetch
googletag.pubads().collapseEmptyDivs(false); // Collapse on no fill
Yeni:
// 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'
});
İlk yükleme ve tekli istek mimarisi (SRA)
Eski:
googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();
Yeni:
googletag.setConfig({
disableInitialLoad: true,
singleRequest: true
});
Geç yükleme
Eski:
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,
});
Yeni:
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,
},
});
Konum
Eski:
googletag.pubads().setLocation('10001,US');
Yeni:
googletag.setConfig({
location: '10001,US'
});
SafeFrame
Eski:
googletag.pubads().setForceSafeFrame(true);
googletag.pubads().setSafeFrameConfig({sandbox: true});
Yeni:
googletag.pubads().setConfig({
safeFrame: {
forceSafeFrame: true,
sandbox: true
}
});
Hedefleme
Eski:
googletag.pubads().setTargeting('interests', 'sports');
googletag.pubads().setTargeting('interests', ['sports', 'music']);
googletag.pubads().clearTargeting('interests');
googletag.pubads().clearTargeting();
Yeni:
// 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
});
Video reklamlar
Eski:
googletag.pubads().enableVideoAds();
googletag.pubads().setVideoContent('video123', 'cms456');
Yeni:
googletag.setConfig({
videoAds: {
enableVideoAds: true,
videoContentId: 'video123',
videoCmsId: 'cms456'
}
});
Alan düzeyinde yapılandırma ayarlama
Aşağıdaki tabloda, eski Slot yapılandırma yöntemleri setConfig ile değiştirilen yöntemlerle eşlenmektedir.
| Özellik | Eski yöntem | setConfig değişimi |
|---|---|---|
| AdSense özellikleri | set(key, value) |
Slot.setConfig({ adsenseAttributes: { [key]: value } })
|
| Kategori hariç tutma | clearCategoryExclusions() |
Slot.setConfig({ categoryExclusion: null })
|
setCategoryExclusion(label) |
Slot.setConfig({ categoryExclusion: [label] })
|
|
| Tıklama URL'si | setClickUrl(url) |
Slot.setConfig({ clickUrl: url })
|
| Boş div'leri daraltma | 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 })
|
|
| Hedefleme | clearTargeting(key) |
Slot.setConfig({ targeting: { [key]: null } })
|
setTargeting(key, value) |
Slot.setConfig({ targeting: { [key]: value } })
|
|
updateTargetingFromMap(config) |
Slot.setConfig({ targeting: config })
|
AdSense özellikleri
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.set('adsense_background_color', '#FFFFFF');
Yeni:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
adsenseAttributes: {
adsense_background_color: '#FFFFFF'
}
});
Kategori hariç tutma
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setCategoryExclusion('AirlineAd');
slot.clearCategoryExclusions();
Yeni:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
// Set category exclusion
slot.setConfig({
categoryExclusion: ['AirlineAd']
});
// Clear category exclusions
slot.setConfig({
categoryExclusion: null
});
Tıklama URLsi
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setClickUrl('http://www.example.com?original_click_url=');
Yeni:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
clickUrl: 'http://www.example.com?original_click_url='
});
Boş div'i daraltma
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setCollapseEmptyDiv(true, true); // Collapse before fetch
Yeni:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
collapseDiv: 'BEFORE_FETCH'
});
SafeFrame
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setForceSafeFrame(true);
slot.setSafeFrameConfig({sandbox: true});
Yeni:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
slot.setConfig({
safeFrame: {
forceSafeFrame: true,
sandbox: true
}
});
Hedefleme
Eski:
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']
});
Yeni:
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']
}
})
Sayfa düzeyinde yapılandırma alma
Aşağıdaki tabloda, eski PubAdsService getter yöntemleri ile bunların getConfig yerine kullanılan yöntemler eşleştirilmektedir.
| Özellik | Eski yöntem | setConfig değişimi |
|---|---|---|
| AdSense özellikleri | get(key) |
googletag.getConfig('adsenseAttributes')
|
getAttributeKeys() |
googletag.getConfig('adsenseAttributes')
|
|
| İlk yükleme | isInitialLoadDisabled() |
googletag.getConfig('disableInitialLoad')
|
| Hedefleme | getTargeting(key) |
googletag.getConfig('targeting')
|
getTargetingKeys() |
googletag.getConfig('targeting')
|
AdSense özellikleri
Eski:
const documentLangauage = googletag.pubads().get('document_language');
const adsenseAttributes = googletag.pubads().getAttributeKeys();
Yeni:
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);
İlk yükleme
Eski:
const isDisabled = googletag.pubads().isInitialLoadDisabled();
Yeni:
const isDisabled = googletag.getConfig('disableInitialLoad').disableInitialLoad;
Hedefleme
Eski:
const targeting = googletag.pubads().getTargeting('interests');
const keys = googletag.pubads().getTargetingKeys();
Yeni:
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 düzeyinde yapılandırma alma
Aşağıdaki tabloda, eski Slot getter yöntemleri ile bunların getConfig yerine kullanılan yöntemler eşleştirilmektedir.
| Özellik | Eski yöntem | setConfig değişimi |
|---|---|---|
| AdSense özellikleri | get(key) |
Slot.getConfig('adsenseAttributes')
|
getAttributeKeys() |
Slot.getConfig('adsenseAttributes')
|
|
| Kategori hariç tutma | getCategoryExclusions() |
Slot.getConfig('categoryExclusion')
|
| Hedefleme | getTargeting(key) |
Slot.getConfig('targeting')
|
getTargetingKeys() |
Slot.getConfig('targeting')
|
AdSense özellikleri
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const bgColor = slot.get('adsense_background_color');
const adsenseAttributes = slot.getAttributeKeys();
Yeni:
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);
Kategori hariç tutma
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const exclusions = slot.getCategoryExclusions();
Yeni:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const exclusions = slot.getConfig('categoryExclusion').categoryExclusion || [];
Hedefleme
Eski:
const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div');
const targeting = slot.getTargeting('allow_expandable');
const keys = slot.getTargetingKeys();
Yeni:
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);