ส่วนขยายโฆษณา

สคริปต์ 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);

หากนําแอปบนอุปกรณ์เคลื่อนที่ทั้งหมดออกจากแคมเปญ แคมเปญจะไม่มีชิ้นงานแอปบนอุปกรณ์เคลื่อนที่อีกต่อไป หากต้องการนําแอปบนอุปกรณ์เคลื่อนที่ทั้งหมดออกจากแคมเปญ คุณต้องเรียกข้อมูลรายการแอปบนอุปกรณ์เคลื่อนที่ของแคมเปญนั้นและนําออกทีละรายการ ขั้นตอนนี้เหมือนกันกับชิ้นงานโฆษณาอื่นๆ ที่รองรับ