AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Ads
1.6K members online now
1.6K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Adwords Budget pacing scriptnot working for new campaigns

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭
Hi fellow Adwords enthusiasts! I use the following script in all my campaigns to properly pace and adjust daily spend for my lifetime budgets. Recently, I have tried to add the script to new campaigns and it has not run properly. It's the exact same script as the one i've always used and it still runs correctly for pre-existing campaigns. I receive the following error: Cannot retrieve the next object: iterator has reached the end. (line 18) Please assist! var START_DATE = new Date('August 23, 2016'); var END_DATE = new Date('Dec 31, 2016'); var TOTAL_BUDGET = 1000 ; var CAMPAIGN_NAME = 'CAMPAIGN NAME HERE'; function main() { // testBudgetStrategy(calculateBudgetEvenly, 10, 500); setNewBudget(calculateBudgetEvenly, CAMPAIGN_NAME, TOTAL_BUDGET, START_DATE, END_DATE); } function setNewBudget(budgetFunction, campaignName, totalBudget, start, end) { var today = new Date(); if (today < start) { Logger.log('Not ready to set budget yet'); return; } var campaign = AdWordsApp.campaigns(). withCondition('CampaignName = "' + campaignName + '"'). get(). next(); var costSoFar = campaign.getStatsFor(dateToString(start), dateToString(end)). getCost(); var daysSoFar = datediff(start, today); var totalDays = datediff(start, end); var newBudget = budgetFunction(costSoFar, totalBudget, daysSoFar, totalDays); campaign.setBudget(newBudget); } function calculateBudgetEvenly(costSoFar, totalBudget, daysSoFar, totalDays) { var daysRemaining = totalDays - daysSoFar; var budgetRemaining = totalBudget - costSoFar; if (daysRemaining <= 0) { return budgetRemaining; } else { return budgetRemaining / daysRemaining; } } function calculateBudgetWeighted(costSoFar, totalBudget, daysSoFar, totalDays) { var daysRemaining = totalDays - daysSoFar; var budgetRemaining = totalBudget - costSoFar; if (daysRemaining <= 0) { return budgetRemaining; } else { return budgetRemaining / (2 * daysRemaining - 1); } } function testBudgetStrategy(budgetFunc, totalDays, totalBudget) { var daysSoFar = 0; var costSoFar = 0; while (daysSoFar <= totalDays + 2) { var newBudget = budgetFunc(costSoFar, totalBudget, daysSoFar, totalDays); Logger.log('Day %s of %s, new budget %s, cost so far %s', daysSoFar + 1, totalDays, newBudget, costSoFar); costSoFar += newBudget; daysSoFar += 1; } } /** * Returns number of days between two dates, rounded up to nearest whole day. */ function datediff(from, to) { var millisPerDay = 1000 * 60 * 60 * 24; return Math.ceil((to - from) / millisPerDay); } function dateToString(date) { return date.getFullYear() + zeroPad(date.getMonth() + 1) + zeroPad(date.getDate()); } function zeroPad(n) { if (n < 10) { return '0' + n; } else { return '' + n; } }

Adwords Budget pacing scriptnot working for new campaigns

Participant ✭ ✭ ☆
# 2
Participant ✭ ✭ ☆

Hi.
You should check CAMPAIGN_NAME variable because you probably have some typo.

And there are no campaigns that meet your criteria.

Re: Adwords Budget pacing scriptnot working for new campaigns

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hey Tomasz_C, thanks for the response! We've checked our spelling and have
tried different naming formats. Any other ideas or alternatives?



Thanks,
Jack