Last active
June 21, 2016 00:31
-
-
Save JasonPellerin/5568cbe4d323b73dc9fb81c441b22933 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
//Last Month Call Details Report - Run Monthly On 1st | |
// Comma-separated list of recipients. Comment out to not send any emails. | |
var RECIPIENT_EMAIL = ''; | |
var SPREADSHEET_URL = 'https://docs.google.com/spreadsheets/d/[YOUR URL HERE]'; | |
function clearSheetData() { | |
var SHEET_NAME = 'Calls Last Month'; | |
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL); | |
var sheet = ss.getSheetByName(SHEET_NAME); | |
sheet.clearContents(); | |
} | |
function openSpreadsheet() { | |
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL); | |
Logger.log(ss.getName()); | |
} | |
function ReportToSpreadsheet() { | |
openSpreadsheet(); | |
clearSheetData(); | |
var SHEET_NAME = 'Calls Last Month'; | |
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL); | |
var sheet = ss.getSheetByName(SHEET_NAME); | |
var report = AdWordsApp.report( | |
'SELECT CampaignName, AdGroupName, CallDuration, CallerNationalDesignatedCode, CallStatus, CallTrackingDisplayLocation, CallType, Date, DayOfWeek, HourOfDay ' + | |
'FROM CALL_METRICS_CALL_DETAILS_REPORT ' + | |
'DURING LAST_MONTH '); | |
var rows = report.rows(); | |
while (rows.hasNext()) { | |
var row = rows.next(); | |
var callDuration = row["CallDuration"]; | |
var callType = row["CallType"]; | |
} | |
report.exportToSheet(ss.getSheetByName(SHEET_NAME)); | |
} | |
function main() { | |
var spreadsheet = SPREADSHEET_URL; | |
Logger.log('Processing Report...\n\r\n\r'); | |
ReportToSpreadsheet() | |
Logger.log('\n\r\n\rCall Details Report Available Here\:\n' + | |
spreadsheet); | |
if (RECIPIENT_EMAIL) { | |
MailApp.sendEmail(RECIPIENT_EMAIL, | |
'Call Details Report Has Been Added To The DashBoard Here', | |
spreadsheet); } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment