-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkCpcPerformance.gs
59 lines (45 loc) · 1.66 KB
/
checkCpcPerformance.gs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
///
// Checks accounts with CPC > 1.01
///
function checkCpcPerformance() {
/// select accounts which fullfill your criteria(conditions)
var accountIterator = MccApp.accounts()
.withCondition("LabelNames CONTAINS 'check_performance'")
.withCondition('AverageCpc > 1.01')
.forDateRange("LAST_MONTH")
.get();
// iterate over selected accounts
while(accountIterator.hasNext()){
var account = accountIterator.next();
var stats = account.getStatsFor('LAST_MONTH');
var accountName = account.getName();
//create a labelIterator with ONLY asanaBoard E-Mails in it
var lblItr= account.labels()
.withCondition("Name CONTAINS 'asana'")
.get();
while(lblItr.hasNext()){
var accountLabel = lblItr.next();
var asanaBoardMail = accountLabel.getName();
//create E-Mail Text
var CpcMail = "\n Account: " + accountName
+ "\n Klicks: " + stats.getClicks().toFixed(0)
+ "\n Average CPC: " + stats.getAverageCpc() + " CHF"
+ "\n Label: " + asanaBoardMail;
//send E-Mail to Asana
//uncomment when testing in Preview and use Loggers, it will also send E-Mails in Preview Mode
/*
MailApp.sendEmail({
to: asanaBoardMail,
subject: 'CPC verbessern, ist höher als 1.01 CHF',
body: 'Der CPC dieses Accounts ist eher schlecht. Schau dir folgende Zahlen an und versuche den CPC zu senken: ' + CpcMail
});
*/
/*
* Logger checks - Use these to test when in Preview Mode
*/
Logger.log(CpcMail);
Logger.log("The Account is " + accountName);
Logger.log("E-Mail was sent to " + asanaBoardMail);
}
}
}