Yapımcılar

Oluşturucular, Google Ads komut dosyalarında öğe oluşturmanın standart yoludur. Oluşturucular, eşzamanlı veya eşzamansız olarak bir Google Ads varlığı derlemenize olanak tanır. Ayrıca işlemin başarılı olup olmadığını kontrol edebilir, sonucuna göre uygun işlemler yapabilirsiniz. Aşağıdaki kod snippet'inde, derleyici kullanarak anahtar kelimenin nasıl oluşturulacağı gösterilmektedir.

// 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 Ads komut dosyaları kullanılarak oluşturulabilen tüm varlıklar bu oluşturucu kalıbını kullanarak bunu yapar.

Performansla ilgili konular

Google Ads komut dosyaları, varsayılan olarak işlemlerini eşzamansız olarak yürütür. Böylece komut dosyaları işlemlerinizi toplu gruplar halinde gruplandırabilir ve yüksek performans elde edebilir. Ancak isSuccessful() ve getResult() gibi İşlem yöntemlerinin çağrılması, Google Ads komut dosyalarını bekleyen işlemler listesini temizlemeye zorlayarak düşük performansa neden olabilir. Bunun yerine, işlemleri barındıracak bir dizi oluşturun ve daha sonra sonuçları almak için bu dizide iterasyon yapın.

Kötü performans İyi performans
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”);
}