-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-campaign-manager-report.js
46 lines (36 loc) · 1.18 KB
/
get-campaign-manager-report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
*
* Export Google Campaign Manager Reports to Google Sheets
*
* Pushes the latest file from a Google Campaign Manager report to Google Sheets
*
* Version: 1.0
*
* Google Apps Script maintained by Frederic Harnois
*
**/
// MODIFY YOUR SETTINGS HERE //
// url of the google sheets where the report will be
var SPREADSHEET_URL = 'INSERT_URL'
// name of the sheet where the report will be
var TAB_NAME = 'INSERT_TAB_NAME'
// DCM profile ID
var PROFILE_ID = 'INSERT_PROFILE_ID'
// DCM report ID
var REPORT_ID = 'INSERT_REPORT_ID'
// DO NOT MODIFY ANYTHING BELOW //
function getDcmReport() {
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = ss.getSheetByName(TAB_NAME);
sheet.clear();
var reportFiles = DoubleClickCampaigns.Reports.Files.list(PROFILE_ID, REPORT_ID, {"maxResults": 1}).items
var url = reportFiles[0].urls.apiUrl
var options = {
'headers': {'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()}
}
var fetchRequest = UrlFetchApp.fetch(url, options)
var results = Utilities.parseCsv(fetchRequest)
sheet.getRange(1,1, results.length, results[0].length).setValues(results);
sheet.deleteRow(results.length)
}