Posts tagged with google-apps-script

I have a google ads script which is failing with the following error.

TypeError: Cannot find default value for object. 

It seems fairly cryptic so im not sure what its referring to.

This is the line that its failing on:

var adOperation = adGroup.newAd().expandedTextAdBuilder()   .newAd()   .expandedTextAdBuilder()   .withHeadline1(expandedTextAd.getHeadline1())   .withHeadline2(expandedTextAd.getHeadline2())   .withDescription1(expandedTextAd.getDescription1())   .withPath1(expandedTextAd.getPath1())   .withPath2(expandedTextAd.getPath2())   .withTrackingTemplate(expandedTextAd.getTrackingTemplate())   .withFinalUrl(expandedTextAd.getFinalUrl())   .build(adGroup); 

I've checked adGroup is set and it is, not sure where to go from here.

Update:

I split the line in to each method call and the line which is failing is line 1

> var adOperation = adGroup .newAd() .expandedTextAdBuilder() 

The problem is I can create a campaign with the Apps Script which shows up in Ads Words Console, the problem is, I can't find it with the Apps Script API. All manually create Campaign can be found. So the question is how can I retrieve the newly created Ads Campaign id.

This is how I create the Ads Campaign, which runs through with no error. Once the code runs through it shows up in the Upload details view.

var upload = AdsApp.bulkUploads()     .newCsvUpload([         "Campaign",         "Start Date",         "Budget",         "Campaign type",         "Bid Strategy Type",         "Campaign state",     ]); upload.append({     "Campaign": "Some Campaign name",     "Start Date": "2020-06-01",     "Budget": "1",     "Campaign type": "video",     "Bid Strategy Type": "Manual CPV",     "Campaign state": "enabled", }); upload.forCampaignManagement(); upload.apply(); 

To retrieve all campaigns I use this code snipped, but the created campaign never shows up.

var campaignIterator = AdsApp.campaigns()     .get(); while (campaignIterator.hasNext()) {     var campaign = campaignIterator.next();     Logger.log('Name: ' + campaign.name); } 

is there a way to easily call a GoogleAds API (TargetingIdeaService to be more precise) from Google Spreadsheet scripts? It looks like there should be an integratation of them but I'm missing it.

I can make calls to others APIs with no issues. I have registered myself on Google Ads and got a test token, which should be changed when I get the definitive one.

Thanks in advance.

Let me start by saying I am not a developer, so please forgive my ignorance here. :)

For the attached script, I am receiving the error: Parsing error. Please check your selector. (line 103)

For the life of me, I can't figure out how to fix this and I've done an extensive online search.

For reference, here is where the script came from: https://searchengineland.com/script-automates-adding-adwords-data-google-spreadsheet-277724

Any solutions would be much appreciated!

(Note that the personal info in the lines 17-21 have been filled out correctly.)

Thanks,

    // AdWords Script: Put Data From AdWords Report In Google Sheets // -------------------------------------------------------------- // Copyright 2017 Optmyzr Inc., All Rights Reserved // // This script takes a Google spreadsheet as input. Based on the column headers, data filters, and date range specified // on this sheet, it will generate different reports. // // The goal is to let users create custom automatic reports with AdWords data that they can then include in an automated reporting // tool like the one offered by Optmyzr. // // // For more PPC management tools, visit www.optmyzr.com // */ var DEBUG = 0; // set to 1 to get more details about what the script does while it runs; default = 0 var REPORT_SHEET_NAME = "report"; // the name of the tab where the report data should go var SETTINGS_SHEET_NAME = "settings"; // the name of the tab where the filters and date range are specified var SPREADSHEET_URL = "https://docs.google.com/spreadsheets/d/1dttJTb547L81XYKdTQ56LcfO9hHhbb9wm06ZY5mKhEo/edit#gid=0"; // The URL to the Google spreadsheet with your report template var EMAIL_ADDRESSES = "exa...@example.com"; // Get notified by email at this address when a new report is ready function main() {   var currentSetting = new Object();   currentSetting.ss = SPREADSHEET_URL;   // Read Settings Sheet   var settingsSheet = SpreadsheetApp.openByUrl(currentSetting.ss).getSheetByName(SETTINGS_SHEET_NAME);   var rows = settingsSheet.getDataRange();   var numRows = rows.getNumRows();   var numCols = rows.getNumColumns();   var values = rows.getValues();   var numSettingsRows = numRows - 1;   var sortString = "";   var filters = new Array();   for(var i = 0; i < numRows; i++) {     var row = values[i];     var settingName = row[0];     var settingOperator = row[1];     var settingValue = row[2];     var dataType = row[3];     debug(settingName + " " + settingOperator + " " + settingValue);     if(settingName.toLowerCase().indexOf("report type") != -1) {       var reportType = settingValue;     } else if(settingName.toLowerCase().indexOf("date range") != -1) {       var dateRange = settingValue;     } else if(settingName.toLowerCase().indexOf("sort order") != -1) {       var sortDirection = dataType || "DESC";       if(settingValue) var sortString = "ORDER BY " + settingValue + " " + sortDirection;       var sortColumnIndex = 1;     }else {       if(settingOperator && settingValue) {         if(dataType.toLowerCase().indexOf("long") != -1 || dataType.toLowerCase().indexOf("double") != -1 || dataType.toLowerCase().indexOf("money") != -1 || dataType.toLowerCase().indexOf("integer") != -1) {           var filter =  settingName + " " + settingOperator + " " + settingValue;         } else {           if(settingValue.indexOf("'") != -1) {             var filter =  settingName + " " + settingOperator + ' "' + settingValue + '"';           } else if(settingValue.indexOf("'") != -1) {             var filter =  settingName + " " + settingOperator + " '" + settingValue + "'";           } else {             var filter =  settingName + " " + settingOperator + " '" + settingValue + "'";           }         }         debug("filter: " + filter)         filters.push(filter);       }     }   }   // Process the report sheet and fill in the data   var reportSheet = SpreadsheetApp.openByUrl(currentSetting.ss).getSheetByName(REPORT_SHEET_NAME);   var rows = reportSheet.getDataRange();   var numRows = rows.getNumRows();   var numCols = rows.getNumColumns();   var values = rows.getValues();   var numSettingsRows = numRows - 1;   // Read Header Row and match names to settings   var headerNames = new Array();   var row = values[0];   for(var i = 0; i < numCols; i++) {     var value = row[i];     headerNames.push(value);     //debug(value);   }    if(reportType.toLowerCase().indexOf("performance") != -1) {     var dateString = ' DURING ' + dateRange;   } else {     var dateString = "";   }   if(filters.length) {     var query = 'SELECT ' + headerNames.join(",") + ' FROM ' + reportType + ' WHERE ' + filters.join(" AND ") + dateString + " " + sortString;   } else {     var query = 'SELECT ' + headerNames.join(",") + ' FROM ' + reportType + dateString + " " + sortString;   }   debug(query);   var report = AdWordsApp.report(query);   try {     report.exportToSheet(reportSheet);     var subject = "Your " + reportType + " for " + dateRange + " for " + AdWordsApp.currentAccount().getName() + " is ready";     var body = "currentSetting.ss<br>You can now add this data to <a href='https://www.optmyzr.com'>Optmyzr</a> or another reporting system.";     MailApp.sendEmail(EMAIL_ADDRESSES, subject, body);     Logger.log("Your report is ready at " + currentSetting.ss);     Logger.log("You can include this in your scheduled Optmyzr reports or another reporting tool.");   } catch (e) {     debug("error: " + e);   } } function debug(text) {   if(DEBUG) Logger.log(text); } 

From within a Google Ads script, I'm trying to create a basic line chart as described here: https://developers.google.com/apps-script/reference/charts/line-chart-builder

The data that I'm looking to chart is Date X Clicks.

I'm able to generate the chart with my data from Google Ads, however, Dates are being formatted as Strings and not actual dates within the chart which is causing other issues.

For example, this code will work with my data but formats the dates as strings within the chart:

var dataBuilder = Charts.newDataTable();   dataBuilder.addColumn(Charts.ColumnType.STRING, 'Date'); dataBuilder.addColumn(Charts.ColumnType.NUMBER, 'Clicks'); 

When I try this code, it does not work:

var dataBuilder = Charts.newDataTable();   dataBuilder.addColumn(Charts.ColumnType.DATE, 'Date'); dataBuilder.addColumn(Charts.ColumnType.NUMBER, 'Clicks'); 

I have tried to convert the date data from this: ["2019-09-27",75],["2019-09-29",102],["2019-9-30",112]

To something like this: ["new Date(2019,9,27)",75],["new Date(2019,9,29)",102],["new Date(2019,9,30)",112]

Based on the documentation that I found here: https://developers.google.com/chart/interactive/docs/datesandtimes

But that does not seem to work.

Any suggestions?