Forked from siliconvallaeys/AWQL to Spreadsheets
Last active
August 10, 2020 06:14
-
-
Save alquanna/e51aebd5a3abaccdcd4d32b1267cc2f1 to your computer and use it in GitHub Desktop.
MCC Version of the AWQL to Spreadsheets script
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
/** | |
AWQL to Spreadsheets - MCC Version | |
> Export account data from one MCC using this Google Ads script | |
> Based on the AWQL to Spreadsheet script by Frederick Vallaeys of Optimyzr.com | |
> Original post: https://www.optmyzr.com/blog/a-script-to-put-any-adwords-data-in-a-spreadsheet/ | |
> This is designed to export data from specific accounts inside one MCC. | |
IMPORTANT: | |
If you want to pull data from all accounts in your MCC, delete Line 12 and change Line 11 to AdsManagerApp.accounts(); only | |
Make sure to fill in the required data in lines 15, 28, and 29. | |
If you are only pulling data for one or two accounts, remove the other Account ID blanks in line 15. | |
**/ | |
function main() { | |
var accountSelector = AdsManagerApp.accounts() | |
.withIds(['[PUT ACCOUNT ID HERE]', '[PUT ACCOUNT ID HERE]', '[PUT ACCOUNT ID HERE]', '[PUT ACCOUNT ID HERE]']); | |
var accountIterator = accountSelector.get(); | |
while (accountIterator.hasNext()) { | |
var account = accountIterator.next(); | |
AdsManagerApp.select(account); | |
var QUERIES = [ {'query' : 'SELECT Date, AccountDescriptiveName, Query, Impressions ' + | |
'FROM SEARCH_QUERY_PERFORMANCE_REPORT '+ | |
'WHERE Impressions > 0 '+ | |
'DURING LAST_WEEK', | |
'spreadsheetUrl' : '[PUT YOUR SPREADSHEET URL HERE]', | |
'tabName' : '[PUT TAB NAME HERE]', | |
'reportVersion' : 'v201809' | |
}]; | |
for(var i in QUERIES) { | |
var queryObject = QUERIES[i]; | |
var query = queryObject.query; | |
var spreadsheetUrl = queryObject.spreadsheetUrl; | |
var tabName = queryObject.tabName; | |
var reportVersion = queryObject.reportVersion; | |
Logger.log(spreadsheetUrl + " " + query); | |
var spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl); | |
var sheet = spreadsheet.getSheetByName(tabName); | |
var report = AdWordsApp.report(query, {apiVersion: reportVersion}); | |
var rows = report.rows(); | |
while (rows.hasNext()) { | |
var row = rows.next(); | |
var DateRange = row["Date"] | |
var AccountName = row["AccountDescriptiveName"]; | |
var Keyword = row["Query"]; | |
var Impressions = row["Impressions"]; | |
sheet.appendRow([DateRange, AccountName, Keyword, Impressions]); | |
} | |
} | |
} | |
} | |
Hi,
unfortunately while trying to run this Google Ads reports the following:
TypeError: Cannot call method "appendRow" of null. (file Code.gs, line 53)Tried to resolve it myself but no luck.
Cheers
Ben
Hi Ben -- sorry for only seeing this comment now.
- Were you able to replace all the blanks/portions in the script that need to be replaced (ex. the ones in lines 14, 27, and 28)?
- Do the accounts that you're trying to pull data from have any running campaigns?
Basically the error message says that it cannot do the appendRow command because something went "null", or did not have any data in them.
Let me know if you still need any help!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
unfortunately while trying to run this Google Ads reports the following:
TypeError: Cannot call method "appendRow" of null. (file Code.gs, line 53)
Tried to resolve it myself but no luck.
Cheers
Ben