-
-
Save adv-zl/ca0e9baf1315ad1f0e0ef6cbdd0b9da7 to your computer and use it in GitHub Desktop.
Расширенная статистика в телеграм от Google ADS
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
function main(){ | |
var currentAccount = AdsApp.currentAccount(); | |
var todayCost = currentAccount.getStatsFor("TODAY").getCost(); // Затраты сегодня | |
var todayClicks = currentAccount.getStatsFor("TODAY").getClicks(); // Клики сегодня | |
var todayCpc = currentAccount.getStatsFor("TODAY").getAverageCpc(); // Цена за клик сегодня | |
var todayInstalls = Number(currentAccount.getStatsFor("TODAY").getConversions()) | |
var cost_per_install = todayCost / todayInstalls | |
var todayImpressions = currentAccount.getStatsFor("TODAY").getImpressions(); // Кол-во показов сегодня | |
var tagAccounts = ''; // Тэг аккаунта для личной статистики | |
sendTelegramMessage( | |
'\n<b>Аккаунт ID:</b> ' + currentAccount.getCustomerId() + | |
'\n<b>Кликов:</b> ' + todayClicks + | |
'\n<b>Цена за клик:</b> ' + todayCpc + | |
'\n<b>Установок:</b> ' + todayInstalls + | |
'\n<b>Цена за установку:</b> ' + round(cost_per_install, 2) + ' ' + currentAccount.getCurrencyCode() + | |
'\n<b>Потрачено:</b> ' + todayCost + ' ' + currentAccount.getCurrencyCode() + | |
'\n<b>Кол-во показов:</b> ' + todayImpressions + | |
'\n<b>Тег:</b> <code>' + tagAccounts + '</code>'); | |
} | |
function round(num, dec) { | |
const [sv, ev] = num.toString().split('e'); | |
return Number(Number(Math.round(parseFloat(sv + 'e' + dec)) + 'e-' + dec) + 'e' + (ev || 0)); | |
} | |
function sendTelegramMessage(text) { | |
var CONFIG2 = { | |
TOKEN: '1343902651:AAElwcOrfiJ1w6_UEaqPdDX4qkOBIuUvcgg', | |
CHAT_ID: '1073595401' | |
}; | |
var telegramUrl = 'https://api.telegram.org/bot' + CONFIG2.TOKEN + '/sendMessage?chat_id=' + CONFIG2.CHAT_ID + '&parse_mode=html&text='; | |
var message = encodeURIComponent(text); | |
var sendMessageUrl = telegramUrl + message; | |
var options = { | |
method: 'POST', | |
contentType: 'application/json' | |
}; | |
UrlFetchApp.fetch(sendMessageUrl, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment