이 가이드에서는 기존 구성 방법에서 새로운 Google 게시자 태그 (GPT) 라이브러리 setConfig 및 getConfig API로 이전하는 방법을 보여주는 예를 제공합니다.
setConfig 및 getConfig API는 페이지 수준 및 슬롯 수준 구성을 모두 관리하는 중앙 집중식 방법을 제공합니다.
페이지 수준 구성 설정
다음 표에서는 기존 PubAdsService 구성 방법을 setConfig 대체 방법으로 매핑합니다.
애드센스 속성
기존:
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 교체 |
|---|---|---|
| 애드센스 속성 | 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 })
|
애드센스 속성
기존:
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 getter 메서드가 getConfig 대체 메서드로 매핑됩니다.
| 기능 | 기존 메서드 | setConfig 교체 |
|---|---|---|
| 애드센스 속성 | get(key) |
googletag.getConfig('adsenseAttributes')
|
getAttributeKeys() |
googletag.getConfig('adsenseAttributes')
|
|
| 초기 로드 | isInitialLoadDisabled() |
googletag.getConfig('disableInitialLoad')
|
| 타겟팅 | getTargeting(key) |
googletag.getConfig('targeting')
|
getTargetingKeys() |
googletag.getConfig('targeting')
|
애드센스 속성
기존:
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 getter 메서드가 getConfig 대체 메서드로 매핑됩니다.
| 기능 | 기존 메서드 | setConfig 교체 |
|---|---|---|
| 애드센스 속성 | get(key) |
Slot.getConfig('adsenseAttributes')
|
getAttributeKeys() |
Slot.getConfig('adsenseAttributes')
|
|
| 카테고리 제외 | getCategoryExclusions() |
Slot.getConfig('categoryExclusion')
|
| 타겟팅 | getTargeting(key) |
Slot.getConfig('targeting')
|
getTargetingKeys() |
Slot.getConfig('targeting')
|
애드센스 속성
기존:
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);