الجهات المنشئة

أدوات الإنشاء هي الطريقة العادية لإنشاء الكيانات في نصوص "إعلانات Google" البرمجية. تتيح لك أدوات الإنشاء إنشاء كيان في "إعلانات Google" بشكلٍ متزامن أو غير متزامن. يمكنك أيضًا التحقّق مما إذا كانت العملية ناجحة أم لا، واتّخاذ الإجراءات المناسبة استنادًا إلى نتيجة العملية. يوضّح مقتطف الرمز البرمجي التالي كيفية إنشاء كلمة رئيسية باستخدام أداة إنشاء.

// Retrieve your ad group.
let adGroup = AdsApp.adGroups().get().next();

// Create a keyword operation.
let keywordOperation = adGroup.newKeywordBuilder()
    .withCpc(1.2)
    .withText("shoes")
    .withFinalUrl("http://www.example.com/shoes")
    .build();

// Optional: examine the outcome. The call to isSuccessful()
// will block until the operation completes.
if (keywordOperation.isSuccessful()) {
  // Get the result.
  let keyword = keywordOperation.getResult();
} else {
  // Handle the errors.
  let errors = keywordOperation.getErrors();
}

يتم إنشاء أي كيان يمكن إنشاؤه باستخدام نصوص "إعلانات Google" البرمجية باستخدام نمط أداة الإنشاء هذا.

اعتبارات الأداء

تنفّذ نصوص "إعلانات Google" البرمجية عملياتها بشكلٍ غير متزامن تلقائيًا. يسمح ذلك للنصوص البرمجية بتجميع عملياتك في دفعات وتحقيق أداء عالٍ. ومع ذلك، يؤدي استدعاء طرق العملية ، مثل isSuccessful() و getResult() ، إلى إجبار نصوص "إعلانات Google" البرمجية على إزالة قائمة العمليات المعلقة، وبالتالي قد يؤدي ذلك إلى ضعف الأداء. بدلاً من ذلك، يمكنك إنشاء مصفوفة لتضمين العمليات، ثم تكرار هذه المصفوفة لاسترداد النتائج.

أداء ضعيف أداء جيد
for (let i = 0; i < keywords.length; i++)
  let keywordOperation = adGroup
    .newKeywordBuilder()
    .withText(keywords[i])
    .build();

  // Bad: retrieving the result in the same
  // loop that creates the operation
  // leads to poor performance.
  let newKeyword =
      keywordOperation.getResult();
  newKeyword.applyLabel("New keywords");
}
// Create an array to hold the operations
let operations = [];

for (let i = 0; i < keywords.length; i++) {
  let keywordOperation = adGroup
    .newKeywordBuilder()
    .withText(keywords[i])
    .build();
  operations.push(keywordOperation);
}

// Process the operations separately. Allows
// Google Ads scripts to group operations into
// batches.
for (let i = 0; i < operations.length; i++) {
  let newKeyword = operations[i].getResult();
  newKeyword.applyLabel("New keywords");
}