英文:
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电子表格。您的列应按以下顺序排列:
- 活动ID
- 匹配类型
- 搜索词
一旦电子表格准备好了,请获取其共享链接 - 具有“查看”访问权限。使用此链接并插入到以下脚本中:
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:
- Campaign ID
- Match Type
- 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 = "SPREADSHEET_URL"; // Replace with your Google Sheet URL
var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getActiveSheet();
var data = sheet.getDataRange().getValues();
for (var i = 1; i < 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 && 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':
// If you want to add a broad match negative keyword, simply remove any special characters
negativeKeywordText = keyword.replace(/[^\w\s]/gi, '');
break;
default:
Logger.log('Invalid match type: ' + matchType + ' for keyword: ' + keyword);
return;
}
campaign.createNegativeKeyword(negativeKeywordText);
Logger.log('Added ' + matchType + ' match negative keyword "' + keyword + '" to campaign ' + campaignId);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论