如何使用Google Ads脚本批量排除搜索词

huangapple go评论104阅读模式
英文:

How to exclude search terms in bulk using Google Ads script

问题

我有一个包含超过500个Google Ads搜索词的列表,想要从它们的广告系列中排除掉。Google Ads界面不允许我批量排除超过500个搜索词。我该如何使用Google Ads脚本来解决这个问题?

英文:

I have a list of Google Ads search terms (more than 500) and want to exclude them from their campaigns. Google Ads UI doesn't allow me to perform bulk exclude more than 500. How can I use a Google Ads script to tackle this issue?

答案1

得分: 0

准备您的搜索词报告作为一个Google电子表格。您的列应按以下顺序排列:

  1. 活动ID
  2. 匹配类型
  3. 搜索词

一旦电子表格准备好了,请获取其共享链接 - 具有“查看”访问权限。使用此链接并插入到以下脚本中:

function main() {
  var SPREADSHEET_URL = "SPREADSHEET_URL"; // 用您的Google表格URL替换
  var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getActiveSheet();
  var data = sheet.getDataRange().getValues();

  for (var i = 1; i < data.length; i++) { // 从1开始以跳过标题行
    var campaignId = data[i][0];
    var matchType = data[i][1].toLowerCase(); // 假设匹配类型在B列中
    var negativeKeyword = data[i][2];

    if (campaignId && negativeKeyword) {
      addNegativeKeyword(campaignId, matchType, negativeKeyword);
    }
  }
}

function addNegativeKeyword(campaignId, matchType, keyword) {
  var campaign = AdsApp.campaigns().withIds([campaignId]).get().next();
  var negativeKeywordText = keyword;

  switch (matchType) {
    case 'exact match':
      negativeKeywordText = '[' + keyword + ']';
      break;
    case 'phrase match':
      negativeKeywordText = '"' + keyword + '"';
      break;
    case 'broad':
      // 如果您想添加宽泛匹配的否定关键字,只需删除任何特殊字符
      negativeKeywordText = keyword.replace(/[^\w\s]/gi, '');
      break;
    default:
      Logger.log('无效的匹配类型:' + matchType + ',关键字:' + keyword);
      return;
  }

  campaign.createNegativeKeyword(negativeKeywordText);
  Logger.log('已将' + matchType + '匹配的否定关键字"' + keyword + '"添加到活动' + campaignId);
}
英文:

Prepare your search terms report as a Google spreadsheet. Your columns should be in this order:

  1. Campaign ID
  2. Match Type
  3. Search Term

Once the spreadsheet is ready, get its sharable link - with the 'View' access. Use this link and insert into the following script:

function main() {
var SPREADSHEET_URL = &quot;SPREADSHEET_URL&quot;; // Replace with your Google Sheet URL
var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getActiveSheet();
var data = sheet.getDataRange().getValues();
for (var i = 1; i &lt; data.length; i++) { // Start from 1 to skip the header row
var campaignId = data[i][0];
var matchType = data[i][1].toLowerCase(); // Assuming the match type is in column B
var negativeKeyword = data[i][2];
if (campaignId &amp;&amp; negativeKeyword) {
addNegativeKeyword(campaignId, matchType, negativeKeyword);
}
}
}
function addNegativeKeyword(campaignId, matchType, keyword) {
var campaign = AdsApp.campaigns().withIds([campaignId]).get().next();
var negativeKeywordText = keyword;
switch (matchType) {
case &#39;exact match&#39;:
negativeKeywordText = &#39;[&#39; + keyword + &#39;]&#39;;
break;
case &#39;phrase match&#39;:
negativeKeywordText = &#39;&quot;&#39; + keyword + &#39;&quot;&#39;;
break;
case &#39;broad&#39;:
// If you want to add a broad match negative keyword, simply remove any special characters
negativeKeywordText = keyword.replace(/[^\w\s]/gi, &#39;&#39;);
break;
default:
Logger.log(&#39;Invalid match type: &#39; + matchType + &#39; for keyword: &#39; + keyword);
return;
}
campaign.createNegativeKeyword(negativeKeywordText);
Logger.log(&#39;Added &#39; + matchType + &#39; match negative keyword &quot;&#39; + keyword + &#39;&quot; to campaign &#39; + campaignId);
}

huangapple
  • 本文由 发表于 2023年8月5日 15:34:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76840590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定