var thisAccount = accountIterator.next();
// Logger.log(thisAccount.getName());
}
MccApp.select(thisAccount);
// Variables
var nameCondition; // string for selector
var totalSpent = 0; // total for campaigns checked
switch (matchType) {
case 'Exact':
nameCondition = 'Name = ' + '"' + thisCampaign + '"';
break;
case 'Contains':
nameCondition = 'Name CONTAINS_IGNORE_CASE ' + '"' + thisCampaign + '"';
break;
default:
nameCondition = "ERROR";
}
// var nameCondition = 'Name = '+'"'+thisCampaign+'"';
// Logger.log("Name condition string is " + nameCondition);
// Iterator
var campaignIterator = AdsApp.campaigns()
.withCondition(nameCondition)
// .withCondition("Status = ENABLED")
.get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
var stats = campaign.getStatsFor(fromDate, toDate);
var campaignCost = stats.getCost();
totalSpent += campaignCost;
var campaignName = campaign.getName();
// Logger.log(" Cost for "+ campaignName + " from "+fromDate + " to "+toDate+ " is " +campaignCost);
}
if (totalSpent >= budgetLimit) {
Logger.log(" Due to spend - pausing " + thisCampaign + ' with total spend $' + totalSpent + ' against $' + budgetLimit + ' limit.');
pauseCampaignByName(thisCampaign, matchType);
}
Logger.log(" " + thisCampaign + ' with total spend $' + totalSpent + ' against $' + budgetLimit + ' limit.');
}
// function checkSpend end
function getDayOfMonth() {
var thisDate = new Date();
var thisDayofMonth = thisDate.getDate();
Logger.log(thisDayofMonth);
return thisDayofMonth;
}
// function labelChecker start
/**
* Checks for the existence of a label on an account
*
* @param {string} labelText Function checks existence of this Label.
* @return {boolean} True if the Label is present.
*/
function labelChecker(labelText) {
if (typeof labelText == 'undefined') {
Logger.log('labelChecker called with no labelText');
return false;
}
var labelSelector = AdsApp.labels()
.withCondition("CampaignsCount > 5")
.orderBy("CampaignsCount DESC");
var labelIterator = labelSelector.get();
while (labelIterator.hasNext()) {
var label = labelIterator.next();
}
}
// function labelChecker end
// function labelCreator start
/**
* Creates a label for an account
*
* @param {string} labelText Function checks existence of this Label.
* @return {boolean} True if the Label is present.
*/
function labelCreator(labelText) {
if (typeof labelText == 'undefined') {
Logger.log('labelCreator called with no labelText');
return false;
}
if (labelChecker(labelText)) {
return true
}
// code below creates the label in Google Ads
}
// function labelCreator end
/**
* xMsg is a wrapper for text to be added to email notifications, or to log to the screen.
*
* @param {string} messageText Content of message to process/display
* @param {boolean} onScreen Display message in log on screen? Defaults to true.
* @param {boolean} addLinefeed Append linefeed to message? Defaults to true.
* @return {string} Returns the original or post-processed message text.
*/
function xMsg(messageText, onScreen, addLinefeed) {
// xMsg v20190814.001
// default value handlers
onScreen = typeof onScreen !== 'undefined' ? onScreen : true;
addLinefeed = typeof addLinefeed !== 'undefined' ? addLinefeed : true;
if (addLinefeed) {
messageText += lineFeed;
}
if (onScreen) {
Logger.log(messageText);
}
return messageText;
}