ผู้สร้าง

เครื่องมือสร้างเป็นวิธีมาตรฐานในการสร้างเอนทิตีในสคริปต์ 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”);
}