Hey guys.
I am having trouble with this script. Basically I am summing up across placements and based on the total performance I want to set the new bid. The script runs perfectly well, also in the preview i get the desired resulst. But when I execute it says in the changes:
Value is lower than required minimum value.
Attempted new value: €0.50.
Does anybody know where this is coming from? The bids are set at the very end of the script. Thanks in advance!!
Regards,
Marius
Script:
//Select all placements from account with cost > 0 and Impr > 0
function main() {
var placementSelector = AdWordsApp.display()
.placements()
.withCondition("Cost > 0")
.withCondition("Impressions > 0")
.forDateRange("LAST_30_DAYS")
//Define variables needed during the script
var i = 0
var placementname = new Array();
var sumCost = 0;
var sumLeads = 0;
var totalCost = new Array();
var totalLeads = new Array();
var CPL = new Array();
var placementIterator = placementSelector.get();
while (placementIterator.hasNext()) {
var placement = placementIterator.next();
//get placement URL as variable
var current_name = placement.getUrl()
//write placement URL into the i-th row of the vector placementname
placementname[i] = current_name
//increase i by 1
i++;
}
var unique = placementname.filter(function(elem, index, array) {
return index == array.indexOf(elem);
})
for(i = 0; i < unique.length; i++){
var placementSelector = AdWordsApp.display()
.placements()
.withCondition("PlacementUrl STARTS_WITH " + "'" + unique[i] + "'")
.withCondition("Cost > 0")
.forDateRange("LAST_30_DAYS")
var placementIterator = placementSelector.get();
while (placementIterator.hasNext()) {
var placement = placementIterator.next();
var current_name = placement.getUrl()
var stats = placement.getStatsFor("LAST_30_DAYS");
if(unique[i] == current_name)
{sumCost += stats.getCost()
sumLeads += stats.getConversions()};
}
totalCost[i] = sumCost;
totalLeads[i] = sumLeads;
CPL[i] = totalCost[i] / totalLeads[i]
sumCost = 0
sumLeads = 0
if(totalCost[i] > 30 && totalLeads[i] == 0){Logger.log(unique[i] + " total cost was: " + totalCost[i] + " total Leads were: " + totalLeads[i] + " CPL: " + CPL[i])};
}
for(i = 0; i < unique.length; i++){
if(totalCost[i] > 25){
var placementSelector = AdWordsApp.display()
.placements()
.withCondition("Cost > 0")
.withCondition("PlacementUrl STARTS_WITH " + "'" + unique[i] + "'")
.forDateRange("LAST_30_DAYS")
var placementIterator = placementSelector.get();
while (placementIterator.hasNext()) {
var placement = placementIterator.next();
var current_name = placement.getUrl()
if(totalCost[i] > 40 && totalLeads[i] == 0){placement.bidding().setCpc(Math.ceil(placement.bidding().getCpc() * 0.2 * 100)/100)};
if(totalCost[i] < 40 && totalCost[i] > 25 && totalLeads[i] == 0){placement.bidding().setCpc(Math.ceil(placement.bidding().getCpc() * 0.5 * 100)/100)};
}
}
}
}