Set Ad Group max CPC same as Product Group max CPC

745 views
Skip to first unread message

Eshop LEDsviti

unread,
Nov 28, 2016, 12:52:47 PM11/28/16
to AdWords Scripts Forum

Hello,

We would like to set new max CPC for Ad Group. 

Now we have max CPC for Ad Group different to max CPC of Product Group inside it. The max CPC of Product Group is the right number we would like to use on Ad Group also. 

Is there any easy procedure how can we solve this in bulk edit? We did not find any similar functionality in Adwords Editor.

Thank You for tips.
Puskarcuk A. | LEDsviti.cz

Tyler Sidell (AdWords Scripts Team)

unread,
Nov 28, 2016, 2:44:05 PM11/28/16
to AdWords Scripts Forum
Hi,

You can edit the max CPC for an ad group through Bulk Uploads. These are the supported entities through Bulk Uploads.

Let us know if there are any additional questions.

Thanks,
Tyler Sidell
AdWords Scripts Team

Eshop LEDsviti

unread,
Nov 29, 2016, 6:55:23 AM11/29/16
to AdWords Scripts Forum
Hi,

Thank You for tip. It works just fine with the spreadsheet. But when we need to edit it on daily basis, script would be better. I found this solution below, but it works the opposite way as intended. It takes CPC from AdGroup to keyword. Don't You know if there is the same solution but it should take keyword CPC and set it to AdGroup (preferably only on certain campaign)?

Thanks for Your help,
Puskarcuk A. | LEDsviti.cz


function main() {

  // GET THE KEYWORDS
  var keywordIterator = AdWordsApp.keywords().get(); // All account's keywords. Can be modified to include conditions
  
  // RUN THROUGH THE KEYWORDS AND CHANGE THEIR MAX CPC
  while (keywordIterator.hasNext()) {
    var keyword = keywordIterator.next();
    var adgroup = keyword.getAdGroup(); // Get the keyword's AdGroup
    var adgroupBid = adgroup.bidding().getCpc(); // Get the AdGroup's Bid
     
    keyword.setMaxCpc(adgroupBid); // Assign the AdGroup bid to the keyword
  }
}

Tyler Sidell (AdWords Scripts Team)

unread,
Nov 29, 2016, 10:44:27 AM11/29/16
to AdWords Scripts Forum
Hi,

You are on the right track with that script.  If you want to take the keyword CPC and set it to the Ad Group CPC you could modify the script as follows:

function main() {
 
var keywordIterator = AdWordsApp.keywords().get();  
 
while (keywordIterator.hasNext()) {
   
var keyword = keywordIterator.next();
   
var cpc = keyword.bidding().getCpc();
   
Logger.log("Keyword CPC: " + cpc);
   
var adgroup = keyword.getAdGroup();
   
if (cpc > 0) {
    adgroup
.bidding().setCpc(cpc);
   
Logger.log("New Ad Group CPC: " + adgroup.bidding().getCpc());
   
}
 
}
}

Let us know if you have any other questions.

Thanks,
Tyler Sidell
AdWords Scripts Team

Eshop LEDsviti

unread,
Nov 30, 2016, 4:12:13 AM11/30/16
to AdWords Scripts Forum on behalf of Tyler Sidell (AdWords Scripts Team)
Hi,

Thanks. Script works well. When I run it with Campaign condition, it fetches no keyword and stops after 2s. I used the same .withCondition() as here https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_keywordselector

Am I missing something?

Thank You,
Puskarcuk A. | LEDsviti.cz

______________________

function main() {
  var keywordIterator = AdWordsApp.keywords()
  .withCondition("CampaignName CONTAINS_IGNORE_CASE 'google-nakupy'")
  .get(); 

--
-- 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 "AdWords Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/4D_MyXkh2c4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/90d35d45-b297-4de9-99d1-8c7585f1d3e0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Tyler Sidell (AdWords Scripts Team)

unread,
Nov 30, 2016, 10:03:38 AM11/30/16
to AdWords Scripts Forum
Hi,

Based on previous issues with your script, we've noticed that 'google-nakupy' is a shopping campaign. These types of campaigns get filtered out of AdWordsApp.keywords() since shopping campaigns don't have positive keywords. I would suggest trying the script with a different campaign, which is not shopping to see if it functions properly.

Let us know if you are still having issues.

Regards,

Tyler Sidell
AdWords Scripts Team

On Wednesday, November 30, 2016 at 4:12:13 AM UTC-5, Eshop LEDsviti wrote:
Hi,

To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Eshop LEDsviti

unread,
Nov 30, 2016, 11:54:41 AM11/30/16
to AdWords Scripts Forum on behalf of Tyler Sidell (AdWords Scripts Team)
Hi,

Thank You for reply. I don't feel we can make it this way.

Finally I would just like to ask Your opinion how would You solve our problem. 
Now we are using bidding script that change max CPC of Ad in specific shopping campaign ("google-nakupy" in our case) but leave max CPC of AdGroup unchanged. This script works very well. 

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?

Thank You very much for Your time :)

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);
}


____________

To unsubscribe from this group and all its topics, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/9fe56a65-6177-4e39-8b11-e87cb171b821%40googlegroups.com.

Tyler Sidell (AdWords Scripts Team)

unread,
Nov 30, 2016, 3:39:02 PM11/30/16
to AdWords Scripts Forum
Hi Puskarcuk,

You could set the max cpc of the ad group and not the product ad.  You would do this by iterating through the product group and then using the getAdGroup() method in order to target that specific ad group.

Example:

function main() {
 
var pgIterator = AdWordsApp.productGroups().get();
 
 
while(pgIterator.hasNext()) {
   
var pg = pgIterator.next();
   
var ag = pg.getAdGroup();
    ag
.bidding().setCpc(cpc);
 
}
}

Thanks,
Tyler Sidell
AdWords Scripts Team

On Wednesday, November 30, 2016 at 11:54:41 AM UTC-5, Eshop LEDsviti wrote:
Hi,

Eshop LEDsviti

unread,
Dec 1, 2016, 11:54:47 AM12/1/16
to AdWords Scripts Forum on behalf of Tyler Sidell (AdWords Scripts Team)
Hi Tyler,

Thanks a lot. 

It logged "invalid argument" because of "0" so I added condition and script started working well now :)

Best Regards,
Ales Puskarcuk | LEDsviti.cz
_______________________

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);
    if(newCpc > 0) { var ag = pg.getAdGroup();
    ag.bidding().setCpc(newCpc); }
    
  } 

To unsubscribe from this group and all its topics, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/42766699-20bc-4602-9fde-79cf63a711d3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages