Oluşturucular, Google Ads komut dosyalarında öğe oluşturmanın standart yoludur. Oluşturucular, bir Google Ads öğesini senkron veya asenkron olarak oluşturmanıza olanak tanır. İşlemin başarılı olup olmadığını da kontrol edebilir ve işlemin sonucuna bağlı olarak uygun işlemleri yapabilirsiniz. Aşağıdaki kod snippet'inde, oluşturucu kullanarak anahtar kelime oluşturma işlemi 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 öğeler, bu oluşturucu kalıbı kullanılarak oluşturulur.
Performansla ilgili konular
Google Ads komut dosyaları, işlemlerini varsayılan olarak eşzamansız şekilde yürütür. Bu sayede, komut dosyaları işlemlerinizi gruplandırarak toplu olarak gerçekleştirebilir ve yüksek performans elde edebilirsiniz. Ancak Operation yöntemlerinin (ör. isSuccessful()
ve getResult()
) çağrılması, Google Ads komut dosyalarının bekleyen işlemler listesini temizlemesine neden olur ve bu nedenle performans düşebilir. Bunun yerine, işlemleri tutacak bir dizi oluşturun ve sonuçları almak için bu dizide yineleme 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”); } |