thank you very much, I'll look into the script you've just sent, even if at first sight this one needs to manually (or remotely) insert the locations already excluded. This sound a bit crazy to me (apologetically of course...I'm a newbie) considering that the campaign data already know which location is used as a target and which one is excluded.
Anyway, doing a step backward, I think that part of the issues is due to the fact that my campaign has no target locations, but are set as "All Countries". Therefore I tried to bulk upload all the countries and then run the script...unfortunately I've had another error that puzzles me..."Impossible to choose as target and exclude at the same time" (probably not the same message you'd get...I'm just translating from italian).
But I do not see where, in my script, I choose any country as target.
function main() {
/////////////////////////////////////////////////////
//
// This script excludes the countries with no conversions in the past 60 days
// with a cost exceeding val_cost as set in line 31
//
// IMPORTANT: Check targetCampaign at line 9 to get proper value in lines 31 and 43
// IMPORTANT: Check average past performances to set proper val_cost limit at line 31
//
/////////////////////////////////////////////////////
var TO_NOTIFY = "mymail";
var targetCampaign = "mycampaignName";
// Calculate the date range "Last 60 Days"
var MILLIS_PER_DAY_PER_60 = 1000 * 60 * 60 * 24 * 60;
var timeZone = AdWordsApp.currentAccount().getTimeZone();
var now = new Date();
var sixtyDaysAgo = new Date(now.getTime() - MILLIS_PER_DAY_PER_60);
var is = Utilities.formatDate(now, timeZone, 'yyyyMMdd');
var was = Utilities.formatDate(sixtyDaysAgo, timeZone, 'yyyyMMdd');
// Extract data for the Last 60 Days
var report = AdWordsApp.report("SELECT Conversions,CampaignName,Clicks,CountryCriteriaId,LocationType,Cost,ConversionValue " + "FROM GEO_PERFORMANCE_REPORT WHERE CampaignStatus='ENABLED' AND LocationType='LOCATION_OF_PRESENCE' DURING "+ was +","+ is,{resolveGeoNames: false});
// Find details of the account
var currentAccount = AdWordsApp.currentAccount();
// Decide to send mail or not
var invia_email = false;
// Extract Rows from Report
var reports = report.rows();
while(reports.hasNext()) {
var thisConvVal = reports.next();
// Extracting data
var val_conversions = thisConvVal.Conversions;
var val_campaignName = thisConvVal.CampaignName;
var val_country = thisConvVal.CountryCriteriaId;
var val_cost = thisConvVal.Cost;
// Select countries with low performances
// IMPORTANT: Check average past performances to set proper val_cost limit
// IMPORTANT: Check correct campaignName
if(val_campaignName == targetCampaign && val_conversions == 0 && val_cost > 14)
{
// Exclude poor performing countries (no Conversions over the Last 60 Days and cost exceeding val_cost)
var campaignIterator = AdWordsApp.campaigns()
.withCondition('Name = "'+targetCampaign+'"')
.get();
if (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
var countryToExclude = Number (val_country);
campaign.excludeLocation(countryToExclude);
}
// print results in log
Logger.log("Fermata nazione "+countryToExclude+" (vedi modifiche per nome) per costo = "+val_cost+"€ e nessuna conversione a partire dal "+was+"");
// send alert email if set true on line 10
if(invia_email == true) {
MailApp.sendEmail(TO_NOTIFY,"ALERT "+currentAccount.getName()+" Excluded Country "+val_country+"","Your AdWords Script excluded CountryId "+val_country+" because of the low performances over the last 60 days: 0 conversions and "+val_cost+"€ cost.");}
}
}
}
Thanks for any further help....