廣告額外資訊

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);

如果廣告活動中移除所有行動應用程式,廣告活動就不會再有行動應用程式額外資訊。若要從廣告活動中移除所有行動應用程式,您必須擷取該廣告活動的行動應用程式清單,然後逐一移除。至於其他支援的廣告額外資訊,程序也相同。