Thank You for reply. I don't feel we can make it this way.
Isn't it possible to make it from the otherside and modify just attached script that it would change also max CPC of AdGroup not just max CPC of product Ad?
Puskarcuk A. | LEDsviti.cz
// Label to filter Campaigns/AdGroups - leave it blank to apply to all campaigns/ad-groups.
var CAMPAIGN_LABEL = ''; //campaign label is case sensitive.
var ADGROUP_LABEL = 'oprava'; //ad-group label is case sensitive.
var TARGET_SEARCH_IS_RANK = 3; // 100 = 1 %
//Converted Clicks Threshold - change number to only impact campaigns/ad-groups with conversions.
var MIN_CONVERTED_CLICKS = 0;
// How much to adjust the bids.
var BID_INCREASE_PCT = 2; // 5%
// Number of Days to look back - leave it to 0 and system will only check data in the last 3 hours.
var LAST_N_DAYS = 30; //search lost is (rank) is delayed by min 48hours.
// Max Cpc Thresholds - absolute value.
var MAX_CPC = 50; //$10
function main() {
log('Started');
var agIds = findAdGroups();
if(agIds.length == 0) {
log('0 Active Campaigns/AdGroups Found');
return;
}
var dateTo = getAdWordsFormattedDate(0, 'yyyyMMdd');
var dateFrom = getAdWordsFormattedDate(LAST_N_DAYS, 'yyyyMMdd');
var DATE_RANGE = dateFrom + ',' + dateTo;
var statsMap = collectAdGroupStats(agIds, DATE_RANGE);
if(Object.keys(statsMap).length == 0) {
log('No Data Found');
return;
}
log('Increasing Bids');
var FACTOR = (1 + BID_INCREASE_PCT/100);
var pgToRaise = AdWordsApp.productGroups()
.withCondition("AdGroupStatus = ENABLED")
.withCondition("CampaignStatus = ENABLED")
.withCondition("AdGroupId IN [" + Object.keys(statsMap).join(',') + "]")
.withCondition('Conversions >= ' + MIN_CONVERTED_CLICKS)
.forDateRange(dateFrom, dateTo)
.get();
log('ProductGroups Found: ' + pgToRaise.totalNumEntities());
while (pgToRaise.hasNext()) {
var pg = pgToRaise.next();
var avgPos = pg.getStatsFor(dateFrom, dateTo).getAveragePosition();
//Current Cpc of the Keyword
var currentCpc = pg.getMaxCpc();
// Skip if Current CPC is already above Max CPC
if(currentCpc >= MAX_CPC) { continue; }
//Calculate New Cpc
var newCpc = currentCpc * FACTOR;
// Apply Stop Limit on New Cpc
if(newCpc > MAX_CPC) { newCpc = MAX_CPC; }
//Update Cpc
pg.setMaxCpc(newCpc);
}
log('Finished');
}
function collectAdGroupStats(agIds,DATE_RANGE) {
var OPTIONS = { includeZeroImpressions : false };
var cols = ['AdGroupId','Impressions','Clicks','Ctr'];
var report = 'ADGROUP_PERFORMANCE_REPORT';
var query = ['select',cols.join(','),'from',report,
'where AdGroupId IN [' + agIds.join(',') + ']',
'and Ctr > ' + (TARGET_SEARCH_IS_RANK/100),
'during',DATE_RANGE].join(' ');
var reportIter = AdWordsApp.report(query, OPTIONS).rows();
var agMap = {};
while(reportIter.hasNext()) {
var reportRow = reportIter.next();
agMap[reportRow.AdGroupId] = reportRow;
}
return agMap;
}
function findAdGroups() {
var campIds = [];
var agIds = [];
if(CAMPAIGN_LABEL.length > 0) {
var camps = AdWordsApp.shoppingCampaigns()
.withCondition('Status = ENABLED')
.withCondition('LabelNames CONTAINS_ANY ["' + CAMPAIGN_LABEL + '"]')
.get();
while(camps.hasNext()) {
campIds.push(camps.next().getId());
}
if(campIds.length == 0) {
log('0 Campaigns Found with label: ' + CAMPAIGN_LABEL);
return agIds;
}
}
var adGroups = AdWordsApp.shoppingAdGroups()
.withCondition('Status = ENABLED')
.withCondition('CampaignStatus = ENABLED')
if(campIds.length > 0) {
adGroups.withCondition('CampaignId IN [' + campIds.join(',') + ']')
}
if(ADGROUP_LABEL.length > 0) {
adGroups.withCondition('LabelNames CONTAINS_ANY ["' + ADGROUP_LABEL + '"]')
}
adGroups = adGroups.get();
while(adGroups.hasNext()){
agIds.push(adGroups.next().getId());
}
return agIds;
}
/**
* Get AdWords Formatted date for n days back
* @param {int} d - Numer of days to go back for start/end date
* @return {String} - Formatted date yyyyMMdd
**/
function getAdWordsFormattedDate(d, format){
var date = new Date();
date.setDate(date.getDate() - d);
return Utilities.formatDate(date,AdWordsApp.currentAccount().getTimeZone(),format);
}
function log(msg) {
var time = Utilities.formatDate(new Date(),AdWordsApp.currentAccount().getTimeZone(), 'yyyy-MM-dd HH:mm:ss.SSS');
Logger.log(time + ' - ' + msg);
}