var config = {
LOG : true,
EMAIL : "X...@XX.com.sg",
EMAIL_INTRO : "The following campaigns have ended!<br />",
EMAIL_SUBJECT : " Ended Campaigns",
DATE_RANGE : "TODAY",
COMPARE : true,
COMPARE_DATERANGE : "LAST_7_DAYS",
ACCOUNT_LABEL : "X"
}
////////////////////////////////////////////////////////////////////
function main() {
var emailContent = config.EMAIL_INTRO;
var accountIterator = MccApp
.accounts()
.withCondition("LabelNames CONTAINS '" + config.ACCOUNT_LABEL + "'")
.get();
while(accountIterator.hasNext()){
var account = accountIterator.next();
MccApp.select(account);
var campaignIterator = AdsApp
.campaigns()
.withCondition("Status = ENABLED")
.withCondition("Impressions = 0")
.withCondition("CampaignExperimentType = BASE")
.withCondition("ServingStatus = SERVING")
.forDateRange("TODAY")
.get();
//Add accountname as heading in email
if(campaignIterator.hasNext()){
emailContent += "<br /><b>" + account.getName() + "</b><br />";
if(config.LOG === true){
Logger.log("Account: " + account.getName());
}
}
while(campaignIterator.hasNext()){
var campaign = campaignIterator.next();
// Only add campaigns with > 0 impressions previous period
if(config.COMPARE === true){
// Check for impressions previous period
if(campaign.getStatsFor(config.COMPARE_DATERANGE).getImpressions() > 0){
if(config.LOG === true){
Logger.log("Campaign: " + campaign.getName());
}
emailContent += campaign.getName() + "<br />";
}
} // compare with previous period
else {
if(config.LOG === true){
Logger.log("Campaign: " + campaign.getName());
}
emailContent += campaign.getName() + "<br />";
}
} // campaignIterator
var shoppingCampaignIterator = AdsApp
.shoppingCampaigns()
.withCondition("Status = ENABLED")
.withCondition("Impressions = 0")
.withCondition("CampaignExperimentType = BASE")
.withCondition("ServingStatus = SERVING")
.forDateRange("TODAY")
.get();
//Add accountname as heading in email
if(shoppingCampaignIterator.hasNext() && !campaignIterator.hasNext()){
emailContent += "<br /><b>" + account.getName() + "</b><br />";
if(config.LOG === true){
Logger.log("Account: " + account.getName());
}
}
while(shoppingCampaignIterator.hasNext()){
var campaign = shoppingCampaignIterator.next();
// Only add campaigns with > 0 impressions previous period
if(config.COMPARE === true){
// Check for impressions previous period
if(campaign.getStatsFor(config.COMPARE_DATERANGE).getImpressions() > 0){
if(config.LOG === true){
Logger.log("Campaign: " + campaign.getName());
}
emailContent += campaign.getName() + "<br />";
}
} // compare with previous period
else {
if(config.LOG === true){
Logger.log("Campaign: " + campaign.getName());
}
emailContent += campaign.getName() + "<br />";
}
} // shoppingCampaignIterator
if(config.LOG === true){
Logger.log("----");
}
} // accountIterator
sendEmail(emailContent);
Logger.log(emailContent);
} // function main
////////////////////////////////////////////////////////////////////
function sendEmail(emailContent) {
MailApp.sendEmail({
to: config.EMAIL,
subject: config.EMAIL_SUBJECT,
htmlBody: emailContent});
} // function sendEmail
Thanks.
|
||||||
|
||||||
var campaignSelector = AdsApp.videoCampaigns() .withCondition("Status = ENABLED") .withCondition("ServingStatus = ENDED") // Option to filter by LabelNames //.withCondition("LabelNames CONTAINS_ANY ['Test']")
Hi All,
@Nils - Thank you for providing a solution to this.
@Avkeren - I would agree with Nils as the provided approach is good to follow. If you would only need to make use of an iterator, then you would just need to migrate the snippet of code our team previously provided to the new script experience environment. I would recommend checking the resource mapping documentation in order to get you started as it states there that the field ServingStatus maps to the field campaign.serving_status. Kindly see below for reference:
var campaignSelector = AdsApp.videoCampaigns() .withCondition("campaign.serving_status = 'ENDED'");
Let us know if you have any further clarifications.
Reference links:
![]() |
Google Ads Scripts Team |
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/LMZUn5cxqu0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/af504fee-c15e-4f5e-bfaf-00c47c53433bn%40googlegroups.com.