Skip to content

Instantly share code, notes, and snippets.

@JasonPellerin
Last active June 21, 2016 00:17
Show Gist options
  • Save JasonPellerin/8610120d435a2fc4cf8a308b52159918 to your computer and use it in GitHub Desktop.
Save JasonPellerin/8610120d435a2fc4cf8a308b52159918 to your computer and use it in GitHub Desktop.
//This Month Call Details Report - Run Hourly
// 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 This 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 This 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 THIS_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