function main() { var account = AdsApp.currentAccount(); var accountId = account.getCustomerId(); var accountCurrency = account.getCurrencyCode(); var dateTime = new Date(); var accountName = "FARM_REPLACE"; var accountStatsToday = account.getStatsFor("TODAY"); var accountStatsYesterday = account.getStatsFor("YESTERDAY"); var accountStatsAllTime = account.getStatsFor("ALL_TIME"); var clicks = accountStatsToday.getClicks(); var conversions = accountStatsToday.getConversions(); var impressions = accountStatsToday.getImpressions(); var averageCpc = accountStatsToday.getAverageCpc().toFixed(2) + " " + accountCurrency; var averageCpm = accountStatsToday.getAverageCpm().toFixed(2) + " " + accountCurrency; var ctr = (accountStatsToday.getCtr() * 100).toFixed(2) + "%"; var yesterdaySpent = (accountStatsYesterday.getCost()).toFixed(2) + " " + accountCurrency; var budgetSpent = (accountStatsAllTime.getCost()).toFixed(2) + " " + accountCurrency; var todaySpent = (accountStatsToday.getCost()).toFixed(2) + " " + accountCurrency; // Получаем дату по времени рекламного аккаунта var formattedDate = getAccountDate(account); var data = { accountId: accountId, accountName: accountName, clicks: clicks, conversions: conversions, impressions: impressions, averageCpc: averageCpc, averageCpm: averageCpm, ctr: ctr, todaySpent: todaySpent, yesterdaySpent: yesterdaySpent, allTimeSpent: budgetSpent, date: formattedDate }; Logger.log("Data being sent to webhook: " + JSON.stringify(data)); sendDataToTelegram(data); sendDataToServer(data); } function getAccountDate(account) { var timeZone = account.getTimeZone(); var now = new Date(); var accountDate = Utilities.formatDate(now, timeZone, "yyyy-MM-dd"); return accountDate; } function sendDataToTelegram(data) { var message = "Account ID: " + data.accountId + "\n" + "Session Name: " + data.accountName + "\n" + "Clicks: " + data.clicks + "\n" + "Conversions: " + data.conversions + "\n" + "Impressions: " + data.impressions + "\n" + "Average CPC: " + data.averageCpc + "\n" + "Average CPM: " + data.averageCpm + "\n" + "CTR: " + data.ctr + "\n" + "Today Spent: " + data.todaySpent + "\n" + "Yesterday Spent: " + data.yesterdaySpent + "\n" + "All Time Spent: " + data.allTimeSpent + "\n" + "Date: " + data.date; var token = "7617678480:AAHaPZj0hdI4TRH4bnQNzPFYtDikvMrDFqM"; var chat_id = "-1002354311914"; var url = 'https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + chat_id + '&text=' + encodeURIComponent(message) + '&parse_mode=html'; var options = { method: "GET", contentType: "application/json", muteHttpExceptions: true, }; try { Logger.log("Sending data to Telegram: " + url); var response = UrlFetchApp.fetch(url, options); Logger.log("Telegram response: " + response.getContentText()); } catch (e) { Logger.log("Error sending data to Telegram: " + e.toString()); } } function sendDataToServer(data) { var serverUrl = 'https://web-skillset.com/stat-folder/index.php'; var options = { method: "POST", contentType: "application/json", payload: JSON.stringify(data) }; try { Logger.log("Sending data to server: " + JSON.stringify(data)); var response = UrlFetchApp.fetch(serverUrl, options); Logger.log("Server response: " + response.getContentText()); } catch (e) { Logger.log("Error sending data to server: " + e.toString()); } }