-
Notifications
You must be signed in to change notification settings - Fork 1
/
Emergency_Actions.js
78 lines (47 loc) · 1.85 KB
/
Emergency_Actions.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var this_label = "CONTAIN_Product-PAUSED";
var description = "Label used to signal which campaigns were paused in an emergency Broken landing pages / etc. handle with care";
var label_color = "red";
var searchparam = "Product"; //not case sensitive
function main(){
var accountSelector = MccApp.accounts()
.forDateRange("LAST 7 DAYS")
.withCondition("Cost > 0")
.orderBy("Cost");
var accountIterator = accountSelector.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
MccApp.select(account);
try{
AdWordsApp.createLabel(this_label, description, label_color);
} catch(e){ Logger.log(e.message);};
/* // For when you want to do something and label at the end
var campaigns_to_work_on = AdWordsApp.campaigns()
.withCondition("Status = ENABLED")
.withCondition("Name CONTAINS_IGNORE_CASE '"+searchparam+"'")
.withCondition("LabelNames CONTAINS_NONE ['"+this_label+"'] ")
.get();
*/
// for when you want to undo something and unlabel at the end
var campaigns_to_work_on = AdWordsApp.campaigns()
.withCondition("LabelNames CONTAINS_ANY ['"+this_label+"'] ")
.get();
while (campaigns_to_work_on.hasNext()) {
//do_something(campaigns_to_work_on.next());
do_something_else(campaigns_to_work_on.next());
}
}
}
function do_something(campaign){ //send a campaign
// simple as this PAUSE then APPLY LABEL
campaign.pause();
if(campaign.isPaused()){
campaign.applyLabel(this_label);
}
}
function campaign_selector(account){
}
function do_something_else(campaign){ //send a campaign
// simple as this PAUSE then APPLY LABEL
campaign.enable();
campaign.removeLabel(this_label);
}