I am trying to achieve a pretty simple task, which unfortunately seems to be actually complex in nature.
I would like to create an automation (any kind of automation) that will send daily Google Ads data to Google Data Studio.
I can't use the Ads connector in Data Studio because I need data from all accounts (the limit is 50). I thought that scheduling the creation of a Google Sheets spreadsheet through the Google Ads Report tool would be enough, since Data Studio accepts Google Sheets as source as well.
The problem is that the scheduled task produces a new Google Sheets spreadsheet (with the same name) everyday, without overwriting the previous file.
I am currently exploring time consuming workarounds that involve Google Ads scripts that query data via AWQL and feed it directly to targeted Google Sheets, but I'm still far from the solution.
I was wondering if there's a way to "trick" the Google Drive file management with a simple overwrite script, in order to keep only the most recent file. I found this solution o Github, but the "unique ID" of the newly created file will prevent me anyway to tell Data Studio which file to point to.
Thank you for your attention.
Best regards,
Kevin
function main() {
var spreadsheetUrl = 'YOUR_SPREADSHEET_URL';
var spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl)
var sheet = spreadsheet.getActiveSheet();
var report = AdsApp.report(
"SELECT CampaignName, AdGroupName, KeywordTextMatchingQuery, Query, Clicks, Ctr, Conversions, CostPerConversion " +
"FROM CAMPAIGN_PERFORMANCE_REPORT " +
"DURING THIS_MONTH "
)
report.exportToSheet(sheet);
Logger.log("Your repot can be found here: " + spreadsheet.getUrl());
}
function main() {
var accountSelector = AdsManagerApp.accounts()
.withLimit(50)
.withCondition("Impressions > 100")
.forDateRange("LAST_MONTH")
.orderBy("Clicks DESC");
accountSelector.executeInParallel("generateReports");
}
function generateReports() {
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});
report.exportToSheet(sheet);
}
}