Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/***********
* Find all the keywords that match a set of criteria. Those keywords
* will be filtered by the set of eligible keywords.
* It returns a list of AdGroup and Keyword Ids to use in a Selector.
***********/
function getDuds(options,eligible_keywords) {
var columns = ['CampaignId',
'AdGroupId',
'Id'];
// Let's add the metric we're using to find the duds
columns.push(options.metric);
var date_range = [
dateStringDaysAgo(options.days_ago),
dateStringDaysAgo(1)
].join(',');
var query_str = [
'SELECT',columns.join(','),
'FROM','KEYWORDS_PERFORMANCE_REPORT',
'WHERE',buildFilterClause(options),
'DURING',date_range
].join(' ');
var report = AdWordsApp.report(query_str);
var rows = report.rows();
var duds = [];
while (rows.hasNext()) {
var row = rows.next();
var key = [row.CampaignId,row.AdGroupId,row.Id].join('-');
// If the keyword isn't eligible, skip it
if(!eligible_keywords[key]) { continue; }
duds.push([row.AdGroupId,row.Id]);
}
return duds;
}
// Helper function to build the AWQL filter
function buildFilterClause(options) {
return [options.metric,'<=',options.threshold].join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment