বিল্ডার

Google Ads স্ক্রিপ্টে এন্টিটি তৈরি করার স্ট্যান্ডার্ড উপায় হল বিল্ডার। বিল্ডার আপনাকে সিঙ্ক্রোনাস বা অ্যাসিঙ্ক্রোনাসভাবে Google Ads এন্টিটি তৈরি করার অনুমতি দেয়। এছাড়াও, আপনি চেক করে দেখতে পারেন যে অপারেশনটি সফল হয়েছে কিনা এবং অপারেশনের ফলাফলের ভিত্তিতে উপযুক্ত অ্যাকশন নিতে পারেন। নিম্নলিখিত কোড স্নিপেট থেকে জানা যায় যে কীভাবে বিল্ডার ব্যবহার করে কীওয়ার্ড তৈরি করতে হয়।

// 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 স্ক্রিপ্ট ব্যবহার করে তৈরি করা যায় এমন যেকোনও এন্টিটি এই বিল্ডার প্যাটার্ন ব্যবহার করে তৈরি করা হয়।

পারফর্ম্যান্স সংক্রান্ত বিবেচনা

ডিফল্ট হিসেবে, Google Ads স্ক্রিপ্ট তার অপারেশন অ্যাসিঙ্ক্রোনাসভাবে এক্সিকিউট করে। এটি স্ক্রিপ্টকে আপনার অপারেশনগুলিকে ব্যাচ হিসাবে গ্রুপ করতে এবং উচ্চ পারফরম্যান্স অর্জন করতে দেয়। তবে, isSuccessful() এবং getResult()-এর মতো অপারেশন মেথড কল করলে, Google Ads স্ক্রিপ্ট তার বাকি থাকা অপারেশনের তালিকা ফ্লাশ করতে বাধ্য হয় এবং এর ফলে পারফর্ম্যান্স খারাপ হতে পারে। পরিবর্তে, অপারেশনগুলি ধরে রাখার জন্য একটি অ্যারে তৈরি করুন, তারপর ফলাফলগুলি পুনরুদ্ধার করতে সেই অ্যারের মাধ্যমে পুনরাবৃত্তি করুন।

খারাপ কার্য-সম্পাদনা ভালো কার্য-সম্পাদনা
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");
}