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"); } |