광고 확장

Google Ads 스크립트는 다음과 같은 광고 확장을 지원합니다.

광고 확장에 대해 자세히 알아보려면 고객센터를 방문하세요.

Google Ads 스크립트를 사용하면 계정에서 지원되는 광고 확장에 액세스할 수 있습니다. 예를 들어 다음 코드 스니펫은 사이트링크에 액세스합니다.

const sitelinkIterator = AdsApp.extensions().sitelinks().get();
for (const sitelink of sitelinkIterator) {
  // Do something with each sitelink
}

각 반복자를 사용하여 지원되는 다른 광고 확장을 비슷하게 가져올 수 있습니다.

제작

Google Ads 스크립트를 사용하면 지원되는 광고 확장을 만들 수 있습니다. 예를 들어 다음 코드 스니펫은 전화번호 작성 도구를 사용하여 계정에 전화번호를 만듭니다.

const phoneNumberBuilder = AdsApp.extensions().newPhoneNumberBuilder();
const newPhoneNumber = phoneNumberBuilder
  .withCountry("US")
  .withPhoneNumber("6502530000")
  .withCallOnly(false)
  .build()
  .getResult();

build()가 호출되면 계정에 전화번호가 생성되지만 아직은 광고와 함께 표시되지 않습니다. 먼저 캠페인 또는 광고그룹에 추가해야 합니다.

// Add a phone number to a campaign.
campaign.addPhoneNumber(newPhoneNumber);

// Add a phone number to an ad group.
adGroup.addPhoneNumber(newPhoneNumber);

지원되는 기타 광고 확장을 해당 빌더와 동일한 방식으로 만들어 캠페인 또는 광고그룹에 연결할 수 있습니다.

통계 가져오기

Google Ads 스크립트를 사용하면 계정, 캠페인 또는 광고그룹 수준에서 지원되는 광고 확장의 통계에 액세스할 수 있습니다.

사이트링크 통계를 가져오는 예는 다음과 같습니다.

// Account-level stats
// Get a sitelink in the account.
const sitelinkIterator = AdsApp.extensions().sitelinks().get();
const sitelink = sitelinkIterator.next();
const sitelinkStats = sitelink.getStatsFor("LAST_30_DAYS");
console.log(sitelinkStats.getClicks());

// Campaign-level stats.
// Get a sitelink in a campaign.
const campaignSitelinkIterator = campaign.extensions().sitelinks().get();
const campaignSitelink = campaignSitelinkIterator.next();
const campaignSitelinkStats = campaignSitelink.getStatsFor("LAST_30_DAYS");
console.log(campaignSitelinkStats.getClicks());

// Ad-group-level stats.
// Get a sitelink in an ad group.
const adGroupSitelinkIterator = adGroup.extensions().sitelinks().get();
const adGroupSitelink = adGroupSitelinkIterator.next();
const adGroupSitelinkStats = adGroupSitelink.getStatsFor("LAST_30_DAYS");
console.log(adGroupSitelinkStats.getClicks());

지원되는 다른 광고 확장에 대한 통계도 비슷한 방식으로 액세스할 수 있습니다.

광고 확장 수정하기

지원되는 기존 광고 확장은 Google Ads 스크립트를 사용하여 수정할 수 있습니다. 예를 들어 다음 코드 스니펫은 기존 사이트링크를 수정합니다.

// Get a sitelink in the account.
const sitelinkIterator = AdsApp.extensions().sitelinks().get();
const sitelink = sitelinkIterator.next();
console.log(sitelink.getLinkText()); // "original text"

// Get a sitelink from a campaign. Assume it's the same one as above.
const campaignSitelinkIterator = campaign.extensions().sitelinks().get();
const campaignSitelink = campaignSitelinkIterator.next();
console.log(campaignSitelink.getLinkText()); // "original text"

// Get a sitelink from an ad group. Assume it's the same one as above.
const adGroupSitelinkIterator = adGroup.extensions().sitelinks().get();
const adGroupSitelink = adGroupSitelinkIterator.next();
console.log(adGroupSitelink.getLinkText()); // "original text"

// Change the sitelink's link text. This change will affect all the campaigns
// and ad groups to which the sitelink belongs.
campaignSitelink.setLinkText("new link text");

// Same text!
console.log(campaignSitelink.getLinkText()); // "new link text"
console.log(adGroupSitelink.getLinkText()); // "new link text"
console.log(sitelink.getLinkText()); // "new link text"

지원되는 다른 광고 확장에도 동일한 개념이 적용됩니다.

광고그룹 수준 광고 확장에 액세스

Google Ads 스크립트를 사용하면 광고그룹 수준의 광고 확장에 액세스할 수 있습니다. 다음 메서드 호출은 광고 그룹에 명시적으로 추가된 전화번호를 반환합니다. 전화번호가 광고그룹이 속한 캠페인에 추가된 경우 전화번호가 해당 광고그룹에서 게재되는 광고에 표시될 수 있더라도 다음 메서드 호출에서는 전화번호가 반환되지 않습니다.

// This will return phone numbers that have been explicitly added to this
// ad group.
const adGroupPhoneNumberIterator = adGroup.extensions().phoneNumbers().get();

지원되는 다른 광고 확장도 유사한 방식으로 광고그룹 수준에서 액세스할 수 있습니다.

계정 수준 광고 확장 액세스

Google Ads 스크립트를 사용하면 계정 수준 광고 확장에 액세스할 수 있습니다. 콜아웃, 모바일 앱, 리뷰는 계정 수준의 광고 확장으로 추가할 수 있지만 계정 수준의 사이트링크와 전화번호는 사용할 수 없습니다. 다음 메서드 호출은 계정에 명시적으로 추가된 콜아웃을 반환합니다.

// This will return callouts that have been explicitly added to your account.
const accountCalloutIterator =
    AdsApp.currentAccount().extensions().callouts().get();

계정 수준의 모바일 앱 및 리뷰에도 비슷한 방식으로 액세스할 수 있습니다.

계정 수준 광고 확장을 추가하는 것은 캠페인 수준 또는 광고그룹 수준 광고 확장을 추가하는 것과 비슷합니다. 다음 예에서는 계정 수준의 콜아웃 광고 확장을 추가하는 방법을 보여줍니다.

// Create a new callout in the account. Without adding the new callout as an ad
// group, campaign or account extension, it won't actually serve.
const calloutBuilder = AdsApp.extensions().newCalloutBuilder();
const newCallout = calloutBuilder.withText("Sample Text").build().getResult();

// Add the new callout as an account-level extension. This enables it to serve
// for all campaigns in the account.
AdsApp.currentAccount().addCallout(newCallout);

계정 수준 모바일 앱 및 리뷰도 비슷한 방식으로 추가할 수 있습니다.

캠페인, 광고그룹, 계정 광고 확장 삭제하기

지원되는 광고 확장은 계정 수준의 캠페인 및 광고그룹에서 삭제할 수 있습니다. Google Ads 스크립트는 계정에서 광고 확장을 한 번에 모두 삭제하는 기능을 지원하지 않습니다.

// Get a mobile app from a campaign.
const campaignMobileAppIterator = campaign.extensions().mobileApps().get();
const campaignMobileApp = campaignMobileAppIterator.next();

// Remove the mobile app.
campaign.removeMobileApp(campaignMobileApp);

// The mobile app still exists in the account and will be returned in the
// following iterator.
const mobileAppIterator = AdsApp.extensions().mobileApps().get();

마찬가지로 광고그룹 수준 또는 계정 수준 모바일 앱을 삭제하는 방법은 다음과 같습니다.

// Get a mobile app from an ad group.
const adGroupMobileAppIterator = adGroup.extensions().mobileApps().get();
const adGroupMobileApp = adGroupMobileAppIterator.next();

// Remove the mobile app.
adGroup.removeMobileApp(adGroupMobileApp);

// Get an account-level mobile app.
const accountMobileAppIterator =
    AdsApp.currentAccount().extensions().mobileApps().get();
const accountMobileApp = accountMobileAppIterator.next();

// Remove the mobile app.
// Note that this removes the mobile app from the account level, so it will
// not serve as an account-level extension, but it will still exist in the
// account. It can still be added to an AdGroup or Campaign, or again as an
// account-level extension in the future.
AdsApp.currentAccount().removeMobileApp(accountMobileApp);

캠페인에서 모바일 앱이 모두 삭제되면 해당 캠페인의 모바일 앱 광고 확장이 더 이상 사용되지 않습니다. 캠페인에서 모든 모바일 앱을 삭제하려면 해당 캠페인의 모바일 앱 목록을 가져와서 한 번에 하나씩 삭제해야 합니다. 지원되는 다른 광고 확장의 절차는 동일합니다.