-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExcludeLowPerformanceDisplayPlacements_MCCLabelFilter
106 lines (83 loc) · 3.8 KB
/
ExcludeLowPerformanceDisplayPlacements_MCCLabelFilter
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* This MCC Level script removes low performance Display placements with more than 1000 impressions AND no clicks AND no view through conversions AND no conversions
* (you can edit these values on the top level variables).
* If one of the placements detected is anonymous.google, the script doesn't exclude it
*
* @author Alberto Esteves
*
* URL: http://www.albertoestevescorreia.com/adwords-script-eliminar-ubicaciones-display-bajo-rendimiento/
*
* Inspired by:
*
* Dawson Reid
* Andrew Breen
*/
var impressionsMinimum = 1000; // Select Display placements which have at least that number of impressions
var clicksLimit = 0; // Select Display placements which have no more than that number of clicks
var conversionsLimit = 0; // Select Display placements which have no more than that number of conversions
var ViewThroughConversionsLimit = 0; // Select Display placements which have no more than that number of post-impression conversions
var mccLabelText = "no label"; // Filter AdWords accounts which have a MCC Account label
// If you don't want to filter by any MCC label, DO NOT make any change in this text
var timePeriod = "ALL_TIME"; // Period of time to analyze. You can choose another value according to https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_campaignselector?hl=es-419#forDateRange_1
// -------------------------------------------------------
function removeLowPerformanceDisplayPlacements (placementSelector) {
var placementIterator = placementSelector.get();
var adGroup, excludeOperation, placement, placementUrl;
while (placementIterator.hasNext()) {
placement = placementIterator.next();
placementUrl = placement.getUrl();
// Logger.log(placementUrl);
if (placementUrl != 'anonymous.google') {
adGroup = placement.getAdGroup();
excludeOperation = adGroup.display().newPlacementBuilder().withUrl(placementUrl).exclude(); // Exclude Display placement detected
if (!excludeOperation.isSuccessful()) {
Logger.log("Could not exclude : " + placementUrl);
}
} else {
Logger.log("Don't exclude anonymous.google.com !");
}
} // End of While
} // End of removeLowPerformanceDisplayPlacements function
function run () {
var placementSelector = AdWordsApp.display().placements()
.withCondition("Clicks <= "+clicksLimit)
.withCondition("Impressions >= "+impressionsMinimum)
.withCondition("Conversions <= "+conversionsLimit)
.withCondition("ViewThroughConversions <= "+ViewThroughConversionsLimit)
.withCondition("CampaignStatus != REMOVED")
.forDateRange(timePeriod);
removeLowPerformanceDisplayPlacements(placementSelector);
} // End of run function
function executeInSequence (sequentialIds, executeSequentiallyFunc) {
// Logger.log('Executing in sequence : ' + sequentialIds);
sequentialIds.forEach(function (accountId) {
var account = MccApp.accounts().withIds([accountId]).get().next();
MccApp.select(account);
executeSequentiallyFunc();
});
} // End of executeInSequence function
function main () {
try {
var accountIterator;
if (mccLabelText != "no label") { // Filter accounts by MCC label
accountIterator = MccApp.accounts().withCondition("LabelNames CONTAINS '" + mccLabelText +"'").orderBy('Name').get();
} else { // Execute script for all accounts
accountIterator = MccApp.accounts().orderBy('Name').get();
}
var accountIds = [];
var accountId;
while (accountIterator.hasNext()) {
accountIds.push(accountId);
accountId = accountIterator.next().getCustomerId();
}
accountIds.push(accountId);
var sequentialIds = accountIds.slice(0);
if (accountIds.length > 0) {
executeInSequence(sequentialIds, run);
}
} catch (exception) {
// not an Mcc
Logger.log('Running on non-MCC account.');
run();
}
}