নির্মাতারা

বিল্ডার হল 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 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”);
}