-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount-structure-checker.js
More file actions
142 lines (121 loc) · 4.31 KB
/
account-structure-checker.js
File metadata and controls
142 lines (121 loc) · 4.31 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// ID: 5c4ab76097d8fd1851cda12252192ba0
/**
*
* Account Structure Checker
*
* This script will check your account for any missing keyword match types
* are output a report with the missing keywords
*
* Version: 1.0
* Google AdWords Script maintained on brainlabsdigital.com
*
**/
/////////////////////////////////////////////////////////////////////////////
// Options
var campaignNameContains = [""];
// Use this if you only want to look at some campaigns.
// For example ["Generic"] would only look at campaigns with 'generic' in the name,
// while ["Generic", "Competitor"] would only look at campaigns with either
// 'generic' or 'competitor' in the name.
// Leave as [] to include all campaigns.
var campaignNameDoesNotContain = [];
// Use this if you want to exclude some campaigns.
// For example ["Brand"] would ignore any campaigns with 'brand' in the name,
// while ["Brand", "Key Terms"] would ignore any campaigns with 'brand' or
// 'key terms' in the name.
// Leave as [] to not exclude any campaigns.
var checkPausedCampaigns = true;
// Set true if you want to include paused campaigns.
// Set false if you want to check enabled campaigns only.
var keywordMatchTypes = ["Exact", "Phrase", "BMM", "Broad"]
// Change this if you only use certain keyword types. For example, in an account
// with only exact and broad match modifier keywords, set this to ["Exact", "BMM"].
var spreadsheetUrl = "";
// The URL of the Google Sheet the results will be put into
/////////////////////////////////////////////////////////////////////////////
// Functions
function main() {
var keywords = {};
var issues = [];
//Check if we need to look at paused campaigns
var campaignStatus = ['ENABLED'];
if (checkPausedCampaigns) {
campaignStatus.push('PAUSED');
}
//Build report query from filters
var whereStatement = 'WHERE CampaignStatus IN ['+ campaignStatus+'] ';
for (var i=0; i < campaignNameDoesNotContain.length; i++) {
whereStatement += " AND CampaignName DOES_NOT_CONTAIN_IGNORE_CASE '" +
campaignNameDoesNotContain[i].replace(/"/g,'\\\"') + "' ";
}
var whereStatementsArray = [];
if (campaignNameContains.length == 0) {
var whereStatementsArray = [whereStatement];
} else {
for (var i = 0; i < campaignNameContains.length; i++) {
whereStatementsArray.push(
whereStatement +
'AND CampaignName CONTAINS_IGNORE_CASE "' +
campaignNameContains[i].replace(/"/g,'\\\"') + '" '
);
}
}
//Get Keyword report
for (var i = 0; i < whereStatementsArray.length; i++) {
var report = AdWordsApp.report(
'SELECT Criteria, KeywordMatchType ' +
'FROM KEYWORDS_PERFORMANCE_REPORT ' +
whereStatementsArray[i] + " " +
"DURING TODAY");
var rows = report.rows();
while (rows.hasNext()) {
var row = rows.next();
var criteria = row['Criteria'];
var keywordMatchType = row['KeywordMatchType'];
if (criteria.indexOf('+') != -1 && keywordMatchType == "Broad") {
keywordMatchType = "BMM";
criteria = criteria.replace(/\+/g, '');
}
if (!(criteria in keywords)) {
keywords[criteria] = {};
}
keywords[criteria][keywordMatchType] = row;
}
}
//Find any missing match type issues
for (var i in keywords) {
var keywordSet = keywords[i];
var keywordIssues = [i, []];
for (var j in keywordMatchTypes) {
var matchType = keywordMatchTypes[j];
if (!(matchType in keywordSet)) {
keywordIssues[1].push(matchType);
}
}
if (keywordIssues[1].length > 0) {
issues.push(keywordIssues);
}
}
//Open and populate spreadsheet with missing match types
var SS = SpreadsheetApp.openByUrl(spreadsheetUrl);
var sheetName = "Keyword Structure Report";
var sheet = SS.getSheetByName(sheetName)
if (!sheet) {
sheet = SS.insertSheet(sheetName);
}
sheet.clear();
var headers = ["Keyword", "Missing Match Types"];
for (var k in issues) {
issues[k][1] = issues[k][1].join(', ');
}
issues.unshift(headers);
sheet.getRange(1,1,issues.length, issues[0].length)
.setValues(issues)
.setFontFamily('Roboto')
.setBorder(true, true, true, true, true, false);
sheet.getRange(1,1,1,headers.length)
.setFontColor('white')
.setFontSize(12)
.setBackground("#3c78d8");
sheet.setHiddenGridlines(true);
}