Skip to content

Instantly share code, notes, and snippets.

@russorat
Created November 13, 2015 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russorat/50b78bd5c1c12f047e1f to your computer and use it in GitHub Desktop.
Save russorat/50b78bd5c1c12f047e1f to your computer and use it in GitHub Desktop.
/***********
* 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