AdWords
3.7K members online now
3.7K members online now
Improve your AdWords performance and boost your ROI, CTR, and Quality Score
Guide Me
star_border
Reply

Bid to Position - Manager Account script- How to set a Max and a min cpc?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello, 

 

I'm trying to customize the Manager Account Bid to Position script. 

I want to set a cpc limit for max and min. 

Below you can find the script

How should I set it? 

 

Thanks in advance, 

Yaniv


/**
* @name MCC Bid To Position
*/


// Ad position you are trying to achieve.
var TARGET_AVERAGE_POSITION = 1.2;

// Once the keywords fall within TOLERANCE of TARGET_AVERAGE_POSITION,
// their bids will no longer be adjusted.
var TOLERANCE = 0.1;

// How much to adjust the bids.
var BID_ADJUSTMENT_COEFFICIENT = 1.05;

// Email address to send the summary report. Leave blank to skip sending emails.
var EMAIL_ADDRESS = '';

// List of email addresses to which summary report will be cc'd. Leave the array
// empty to skip sending email copies.
var EMAIL_CC_ADDRESS = [''];

 

/*
* The main method.
*/
function main() {
accIter = MccApp.accounts()
.withIds(['']);
accIter.executeInParallel('adjustBids', 'sendEmail');

}

/**
* Adjusts the bid for a single account.
*
* @return {Object} a result object that has details about how many keyword
* bids were adjusted.
*/
function adjustBids() {
var raisedKeywordCount = raiseKeywordBids();
var loweredKeywordCount = lowerKeywordBids();
var retval = {'raised': raisedKeywordCount, 'lowered': loweredKeywordCount};
return JSON.stringify(retval);
}

/**
* Raises the bids for keywords in an account.
*
* @return {number} The number of keywords whose bids were raised.
*/
function raiseKeywordBids() {
var keywordsToRaise = getKeywordsToRaise();

while (keywordsToRaise.hasNext()) {
var keyword = keywordsToRaise.next();
keyword.bidding().setCpc(getIncreasedCpc(keyword.bidding().getCpc()));
}
return keywordsToRaise.totalNumEntities();
}

/**
* Lowers the bids for keywords in an account.
*
* @return {number} The number of keywords whose bids were lowered.
*/
function lowerKeywordBids() {
var keywordsToLower = getKeywordsToLower();

while (keywordsToLower.hasNext()) {
var keyword = keywordsToLower.next();
keyword.bidding().setCpc(getDecreasedCpc(keyword.bidding().getCpc()));
}
return keywordsToLower.totalNumEntities();
}

/**
* Increases a given CPC using the bid adjustment coefficient.
* @Param {number} cpc - the CPC to increase
* @return {number} the new CPC
*/
function getIncreasedCpc(cpc) {
return cpc * BID_ADJUSTMENT_COEFFICIENT
}

/**
* Decreases a given CPC using the bid adjustment coefficient.
* @Param {number} cpc - the CPC to decrease
* @return {number} the new CPC
*/
function getDecreasedCpc(cpc) {
return cpc / BID_ADJUSTMENT_COEFFICIENT;
}

/**
* Gets an iterator of the keywords that need to have their CPC raised.
* @return {Iterator} an iterator of the keywords
*/
function getKeywordsToRaise() {
// Condition to raise bid: Average position is greater (worse) than
// target + tolerance
return AdWordsApp.keywords()
.withCondition('Status = ENABLED')
.withCondition("CampaignName CONTAINS_IGNORE_CASE ''")
.withCondition(
'AveragePosition > ' + (TARGET_AVERAGE_POSITION + TOLERANCE))
.orderBy('AveragePosition ASC')
.forDateRange('LAST_7_DAYS')
.get();
}

/**
* Gets an iterator of the keywords that need to have their CPC lowered.
* @return {Iterator} an iterator of the keywords
*/
function getKeywordsToLower() {
// Conditions to lower bid: Ctr greater than 1% AND
// average position less (better) than target - tolerance
return AdWordsApp.keywords()
.withCondition("CampaignName CONTAINS_IGNORE_CASE ''")
.withCondition('Ctr > 0.01')
.withCondition(
'AveragePosition < ' + (TARGET_AVERAGE_POSITION - TOLERANCE))
.withCondition('Status = ENABLED')
.orderBy('AveragePosition DESC')
.forDateRange('LAST_7_DAYS')
.get();
}

/**
* Send summary report email to users.
*
* @Param {Array.<ExecutionResult>} results the ExecutionResult array returned
* by executeInParallel method.
*/
function sendEmail(results) {
var emailBody = [];

emailBody.push(
'<html>', '<body>',
'<table width=800 cellpadding=0 border=0 cellspacing=0>', '<tr>',
'<td colspan=2 align=right>',
'<div style=\'font: italic normal 10pt Times New Roman, serif; ' +
'margin: 0; color: #666; padding-right: 5px;\'>' +
'Powered by AdWords Scripts</div>',
'</td>', '</tr>', '<tr bgcolor=\'#3c78d8\'>', '<td width=500>',
'<div style=\'font: normal 18pt verdana, sans-serif; ' +
'padding: 3px 10px; color: white\'>' +
'BidToPosition summary report</div>',
'</td>', '<td align=right>',
'<div style=\'font: normal 18pt verdana, sans-serif; ' +
'padding: 3px 10px; color: white\'>',
AdWordsApp.currentAccount().getCustomerId(), '</h1>', '</td>', '</tr>',
'</table>', '<table width=800 cellpadding=0 border=0 cellspacing=0>',
'<tr bgcolor=\'#ddd\'>', '<td style=\'font: 12pt verdana, sans-serif; ' +
'padding: 5px 0px 5px 5px; background-color: #ddd; ' +
'text-align: left\'>Customer ID</td>',
'<td style=\'font: 12pt verdana, sans-serif; ' +
'padding: 5px 0px 5px 5px; background-color: #ddd; ' +
'text-align: left\'>Results</td>',
'</tr>', emailRows(results), '</table>', '</body>', '</html>');


if (EMAIL_ADDRESS != '') {
MailApp.sendEmail(
EMAIL_ADDRESS, 'BidToPosition summary report', '',
{htmlBody: emailBody.join('\n'), cc: EMAIL_CC_ADDRESS.join(',')});
}
}

/**
* Constructs email rows for each customer id processed by the script.
*
* @Param {Array.<ExecutionResult>} results the ExecutionResult array returned
* by executeInParallel method.
* @return {string} the html body corresponding to the customer ids processed
* by the script and its results.
*/
function emailRows(results) {
var rows = [];
for (var i = 0; i < results.length; i++) {
var result = results[i];

rows.push(
'<tr>',
'<td style=\'padding: 5px 10px\'>' + result.getCustomerId() + '</td>',
'<td style=\'padding: 0px 10px\'>' + getResultDescription(result) +
'</td>',
'</tr>');
}
return rows.join('\n');
}

/**
* Gets a description text for execution results on a customer id.
*
* @Param {ExecutionResult} result the ExecutionResult object returned
* by executeInParallel method for the customer id.
* @return {string} a processed text that summarizes the execution result.
*/
function getResultDescription(result) {
if (result.getStatus() == 'OK') {
var retval = JSON.parse(result.getReturnValue());
return 'Raised : ' + retval.raised + ' < br / > ' +
'Lowered : ' + retval.lowered;
} else if (result.getStatus() == 'ERROR') {
return result.getError();
} else {
return 'Script timed out.';
}
}

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Yaniv N
May 2017

Re: Bid to Position - Manager Account script- How to set a Max and a min cpc?

Top Contributor
# 2
Top Contributor

Hi @Yaniv N you'll need to add just a few extra lines of code to achieve this, as follows.

 

Firstly, at the top of the script define your max and min CPC values, like so:

// upper limit for CPC values
var MAX_CPC = 1.00;
// lower limit for CPC values
var MIN_CPC = 0.10;

Obviously you'll want to edit this to provide your own values for the Max and Min figures.

 

Now look through the code for the line:

keyword.bidding().setCpc(getIncreasedCpc(keyword.bidding().getCpc()));

and replace that line with these:

var newCPC = getIncreasedCpc(keyword.bidding().getCpc());
newCPC = (newCPC < MIN_CPC)? MIN_CPC : newCPC;
newCPC = (newCPC > MAX_CPC)? MAX_CPC : newCPC;
keyword.bidding().setCpc(newCPC);

Now search for the line:

keyword.bidding().setCpc(getDecreasedCpc(keyword.bidding().getCpc()));

as follows:

var newCPC = getDecreasedCpc(keyword.bidding().getCpc());
newCPC = (newCPC < MIN_CPC)? MIN_CPC : newCPC;
newCPC = (newCPC > MAX_CPC)? MAX_CPC : newCPC;
keyword.bidding().setCpc(newCPC);

and you're all done!

 

This is a fairly clumsy way to do this, personally I wouldn't have structured the script in this way, but this is the quickest and easiest route to what you want.  Bear in mind, of course, that if your Maximum CPC setting is too low, the whole purpose of the script (to achieve a certain position) may be defeated.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Yaniv N
May 2017

Re: Bid to Position - Manager Account script- How to set a Max and a min cpc?

Top Contributor
# 2
Top Contributor

Hi @Yaniv N you'll need to add just a few extra lines of code to achieve this, as follows.

 

Firstly, at the top of the script define your max and min CPC values, like so:

// upper limit for CPC values
var MAX_CPC = 1.00;
// lower limit for CPC values
var MIN_CPC = 0.10;

Obviously you'll want to edit this to provide your own values for the Max and Min figures.

 

Now look through the code for the line:

keyword.bidding().setCpc(getIncreasedCpc(keyword.bidding().getCpc()));

and replace that line with these:

var newCPC = getIncreasedCpc(keyword.bidding().getCpc());
newCPC = (newCPC < MIN_CPC)? MIN_CPC : newCPC;
newCPC = (newCPC > MAX_CPC)? MAX_CPC : newCPC;
keyword.bidding().setCpc(newCPC);

Now search for the line:

keyword.bidding().setCpc(getDecreasedCpc(keyword.bidding().getCpc()));

as follows:

var newCPC = getDecreasedCpc(keyword.bidding().getCpc());
newCPC = (newCPC < MIN_CPC)? MIN_CPC : newCPC;
newCPC = (newCPC > MAX_CPC)? MAX_CPC : newCPC;
keyword.bidding().setCpc(newCPC);

and you're all done!

 

This is a fairly clumsy way to do this, personally I wouldn't have structured the script in this way, but this is the quickest and easiest route to what you want.  Bear in mind, of course, that if your Maximum CPC setting is too low, the whole purpose of the script (to achieve a certain position) may be defeated.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Bid to Position - Manager Account script- How to set a Max and a min cpc?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks @Jon_Gritton

I set the changes you mention. 

When I tried to preview it,  I get: 

"Missing argument: cpc (line 65)"

 

keyword.bidding().setCpc(newCPC);

 

Any ideas? 

Bid to Position - Manager Account script- How to set a Max and a min cpc?

Top Contributor
# 4
Top Contributor

Hi @Yaniv N that error suggests that "newCPC" isn't defined.  Can you post your entire script so I can check it?

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Bid to Position - Manager Account script- How to set a Max and a min cpc?

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Solve it! 

Thanks!