Created
March 15, 2016 04:15
-
-
Save jrjames83/cc23b618f07a9c47e324 to your computer and use it in GitHub Desktop.
adwords keyword bidding skeleton
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
| function main() { | |
| // Set-up dates for lookback period control | |
| // | |
| Number.prototype.padZero= function(len){ | |
| var s= String(this), c= '0'; | |
| len= len || 2; | |
| while(s.length < len) s= c + s; | |
| return s; | |
| } | |
| Date.prototype.yyyymmdd = function() { | |
| var yyyy = this.getFullYear().toString(); | |
| var mm = (this.getMonth()+1).padZero().toString(); | |
| var dd = this.getDate().padZero().toString(); | |
| return "".concat(yyyy).concat(mm).concat(dd); // padding | |
| }; | |
| function makeDate(daysAgo) { | |
| var today = new Date(); | |
| var priorDate = new Date().setDate(today.getDate()-daysAgo) | |
| return new Date(priorDate).yyyymmdd(); | |
| } | |
| // Set-up Lookback Period - change this stuff depending | |
| var daysago7 = makeDate(7); | |
| var daysago14 = makeDate(14); | |
| var keywordSelector = AdWordsApp | |
| .keywords() | |
| .withCondition("Clicks > 100") | |
| .forDateRange(daysago14,daysago7) | |
| .orderBy("Clicks DESC"); | |
| var keywordIterator = keywordSelector.get(); | |
| while (keywordIterator.hasNext()) { | |
| var keyword = keywordIterator.next(); | |
| var stats = keyword.getStatsFor(daysago14,daysago7) | |
| var conv = stats.getConvertedClicks() | |
| var cost = stats.getCost(); | |
| var cpa = cost / conv; | |
| if(cpa > 20) { | |
| Logger.log("Too much"); // execute action or tier it out here | |
| // use getCpc and setCpc iteratively based on tiers or conditions | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment