Last active
June 23, 2023 10:54
-
-
Save teamambire/1af1d05f23dba473b1191f5d9060089b to your computer and use it in GitHub Desktop.
This file contains 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
/************************************************* | |
* Google Ads Budgets By Day Of The Week | |
* @version: 1.0 | |
* @author: Andrea Atzori (Ambire) | |
* https://ambire.com.au/ | |
*************************************************** | |
* YOU MUST CREATE A COPY OF THE GOOGLE SHEET: https://docs.google.com/spreadsheets/d/1VuyiTmBiutnxqCxXOur5brW1_WGFtJxsteNQ-OMK04k/copy | |
*************************************************** | |
*/ | |
function main() { | |
var sheetId = 'ADD-THE-GOOGLE-SHEETS-ID-HERE' | |
var sheet = SpreadsheetApp.openById(sheetId) | |
var budgetsTab = sheet.getSheetByName('today') | |
var lastRow = budgetsTab.getLastRow()-1 | |
var logSheet = SpreadsheetApp.openById('ADD-THE-GOOGLE-SHEETS-ID-HERE').getSheetByName('change log') | |
try{ | |
var budgets = budgetsTab.getRange(2,1,lastRow,budgetsTab.getLastColumn()).getValues() | |
} | |
catch (e) | |
{ | |
Logger.log("No budgets for today found") | |
} | |
for (var i = 0; i<lastRow; i++) | |
{ | |
if(i > 0 && budgets[i][1] != accountId) | |
{ var accountId = budgets[i][1] | |
var account = MccApp.accounts().withIds([accountId]).get().next() | |
MccApp.select(account) | |
} | |
else | |
{ | |
var accountId = budgets[i][1] | |
var account = MccApp.accounts().withIds([accountId]).get().next() | |
MccApp.select(account) | |
} | |
var accountName = account.getName() | |
var condition = 'campaign_budget.name = ' + '"' + budgets[i][2] + '"' | |
try | |
{ | |
var campaign = AdsApp.budgets().withCondition(condition).get().next() | |
var campaignName = campaign.getName() | |
var campaignId = campaign.getId() | |
var changeType = 'DAY OF WEEK' | |
var previousBudget = campaign.getAmount() | |
var newBudget = budgets[i][3] | |
row = [Utilities.formatDate(new Date(), "Australia/Sydney", "YYYY-MM-dd") ,accountId, accountName, campaignId, campaignName, changeType, previousBudget, newBudget] | |
logSheet.appendRow(row) | |
campaign.setAmount(newBudget) | |
} | |
catch(e) | |
{ | |
Logger.log("Campaign not found " + condition) | |
} | |
} | |
} |
Hi! I got the same error, but managed to fix it. You just need to name the sheetnames right. That is; the names within the sheet are 0.today, 1.allocation etc. The names used in the script are 'today' and 'change log'. Sollution: Either adjust the names in the script to '0.today' and '4.change log' (see below) of adjust the sheetnames to 'today' and 'change log'.
var sheet = SpreadsheetApp.openById(sheetId)
var budgetsTab = sheet.getSheetByName('0.today')
var lastRow = budgetsTab.getLastRow()-1
var logSheet = SpreadsheetApp.openById('1uXTlxOwwpT6sXqkjjf-lQrfDCKwZ5OLFkNnCImXwQoU').getSheetByName('4.change log')
Hi everyone!! I had the same error as Erica, can anyone help me, please? Thank you very much :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, GitHub Community. I'm new to using Google Ads Script. I was trying to implement this and tried multiple times, I'm encountering this error when running preview. Hope I could get a help here. Thanks a lot!