Created
November 13, 2015 08:43
-
-
Save russorat/50b78bd5c1c12f047e1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********** | |
* 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