關鍵字
    
    
      
    
    
      
      透過集合功能整理內容
    
    
      
      你可以依據偏好儲存及分類內容。
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
    
在現有廣告群組中建立關鍵字
function createHatsKeyword() {
  // This example snippet creates a broad match keyword for "hats".  Keywords
  // can be created with many optional settings, such as a max CPC bid, tracking
  // URL templates, and more.  Please customize this example for your specific
  // use case.  For more details about keyword builder options, see
  // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_keywordbuilder.
  const adGroupName = 'Ad group 1';
  const adGroupIterator = AdsApp.adGroups()
        .withCondition(`ad_group.name = "${adGroupName}"`)
        .get();
  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group found with name "${adGroupName}"`);
  }
  const adGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${adGroupName}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
  }
  const keywordOperation = adGroup.newKeywordBuilder()
        .withText('hats')
        .withCpc(1.25)
        .withFinalUrl('https://www.example.com')
        .build();
  return keywordOperation;
}
暫停廣告群組中的現有關鍵字
function pauseKeywordInAdGroup(keywordText, adGroupName) {
  const adGroupIterator = AdsApp.adGroups()
        .withCondition(`ad_group.name = "${adGroupName}"`)
        .get();
  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group found with name "${adGroupName}"`);
  }
  const adGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${adGroupName}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
  }
  for (const keyword of adGroup.keywords().withCondition(
      `ad_group_criterion.keyword.text = "${keywordText}"`)) {
    keyword.pause();
  }
}
擷取廣告群組中的所有關鍵字
function getKeywordsInAdGroup(adGroupName) {
  const keywordIterator = AdsApp.keywords()
        .withCondition(`ad_group.name = "${adGroupName}"`)
        .get();
  console.log(`Ad Group "${adGroupName}" has ${
      keywordIterator.totalNumEntities()} keywords`);
  return keywordIterator;
}
記錄廣告群組內所有關鍵字的統計資料
function logKeywordStatsForAdGroup() {
  // This example snippet prints click and impression statistics to the script
  // execution log.  Please customize this example for your specific use case.
  // For all the kinds of statistics that can be logged, see
  // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_stats.
  const adGroupName = 'Ad group 1';
  const adGroupIterator = AdsApp.adGroups()
        .withCondition(`ad_group.name = "${adGroupName}"`)
        .get();
  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group found with name "${adGroupName}"`);
  }
  const adGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${adGroupName}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
  }
  for (const keyword of adGroup.keywords()) {
    let stats = keyword.getStatsFor('LAST_MONTH');
    console.log(`Ad Group: "${adGroup.getName()}"`);
    console.log(`Keyword: "${keyword.getText()}"`);
    console.log(`Clicks: ${stats.getClicks()}`);
    console.log(`Impressions: ${stats.getImpressions()}`);
    console.log('--------------------');
  }
}
  
  
  
  
    
  
 
  
    
    
      
       
    
    
  
  
  除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
  上次更新時間:2025-08-21 (世界標準時間)。
  
  
  
    
      [null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[],[]]