سازندگان
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
سازندگان روش استاندارد برای ایجاد موجودیت در اسکریپت های تبلیغاتی گوگل هستند. سازندگان به شما این امکان را می دهند که یک موجودیت 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");
} |
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-09-03 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-09-03 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eBuilders are the standard way to create entities in Google Ads Scripts, offering synchronous and asynchronous options with success checks.\u003c/p\u003e\n"],["\u003cp\u003eThe builder pattern is utilized for creating any entity within Google Ads scripts.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Ads scripts default to asynchronous operations for performance, but retrieving results immediately can hinder this; it's recommended to batch operations for efficiency.\u003c/p\u003e\n"],["\u003cp\u003eInstead of retrieving results directly after each operation, store operations in an array and process them separately to enhance script performance by allowing for batching.\u003c/p\u003e\n"]]],[],null,["# Builders are the standard way to create entities in Google Ads scripts. Builders allow\nyou to build a Google Ads entity either synchronously or asynchronously. You\ncan also check whether the operation was successful or not, and take\nappropriate actions depending on the operation's outcome. The following code\nsnippet shows how to create a keyword using a builder. \n\n // Retrieve your ad group.\n let adGroup = AdsApp.adGroups().get().next();\n\n // Create a keyword operation.\n let keywordOperation = adGroup.newKeywordBuilder()\n .withCpc(1.2)\n .withText(\"shoes\")\n .withFinalUrl(\"http://www.example.com/shoes\")\n .build();\n\n // Optional: examine the outcome. The call to isSuccessful()\n // will block until the operation completes.\n if (keywordOperation.isSuccessful()) {\n // Get the result.\n let keyword = keywordOperation.getResult();\n } else {\n // Handle the errors.\n let errors = keywordOperation.getErrors();\n }\n\nAny entity that can be created using Google Ads scripts does so using this builder\npattern.\n\nPerformance considerations\n--------------------------\n\nBy default, Google Ads scripts executes its operations asynchronously. This\nallows scripts to group your operations as batches, and achieve high\nperformance. However, calling the\n[Operation](/google-ads/scripts/docs/reference/adsapp/adsapp_sitelinkoperation)\nmethods like\n[`isSuccessful()`](/google-ads/scripts/docs/reference/adsapp/adsapp_sitelinkoperation#isSuccessful)\nand\n[`getResult()`](/google-ads/scripts/docs/reference/adsapp/adsapp_sitelinkoperation#getResult)\nforces Google Ads scripts to flush its pending operations list, and thus may lead to\npoor performance. Instead, create an array to hold the operations, then iterate\nthrough that array to retrieve the results.\n\n| Poor performance | Good performance |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ```transact-sql for (let i = 0; i \u003c 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\"); } ``` | ```transact-sql // Create an array to hold the operations let operations = []; for (let i = 0; i \u003c 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 \u003c operations.length; i++) { let newKeyword = operations[i].getResult(); newKeyword.applyLabel(\"New keywords\"); } ``` |"]]