پسوندهای تبلیغاتی

اسکریپت‌های 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 به شما امکان می‌دهند به برنامه‌های افزودنی تبلیغات در سطح گروه‌های تبلیغاتی دسترسی داشته باشید. فراخوانی روش زیر شماره تلفن هایی را که صریحاً به یک گروه تبلیغاتی اضافه شده اند برمی گرداند. توجه داشته باشید که اگر شماره تلفن‌هایی به کمپینی که گروه تبلیغاتی به آن تعلق دارد اضافه شده باشد، روش فراخوانی زیر آنها را باز نمی‌گرداند ، حتی زمانی که شماره تلفن‌ها واجد شرایط نمایش در آگهی‌های ارائه‌شده از آن گروه تبلیغاتی باشند.

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

اگر همه برنامه‌های تلفن همراه از یک کمپین حذف شوند، کمپین دیگر پسوند برنامه تلفن همراه نخواهد داشت. برای حذف همه برنامه‌های تلفن همراه از کمپین خود، باید فهرست برنامه‌های تلفن همراه آن کمپین را بازیابی کنید و آنها را یکی یکی حذف کنید. این روش برای سایر پسوندهای تبلیغاتی پشتیبانی شده یکسان است.