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

Cost/Conversions bidding script problem

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Hi everyone,

 

I'm trying to learn Adwords scripting by tinkering with some of the code already provided by Google. I'm trying to modify the average position bidding script that Google has given so that it does the following:

 

increase bids bids by x amount if     1- average position is less than x

                                                                2 - conversions are more than x

                                                                3 - cost/conversions is less than x

 

Can someone help me with this please? So far I've done this (I understand what I've done is probably going to be so simple it'll make some of you laugh but hey, every one has to start from somewhere Smiley Happy ).

 

the problem is in this line:

 

.withCondition("Cost" / "ConvertedClicks > 5") 

 

 

 

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

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

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

function main() {
   ClickConvIncreaser();
 }

function ClickConvIncreaser() {
  // Condition to raise bid: Average position is greater (worse) than
  // target + tolerance
  var CCIncrease = AdWordsApp.keywords()
    .withCondition("Status = ENABLED")
    .withCondition("ConvertedClicks > 2")
    .withCondition("AveragePosition > " + (TARGET_AVERAGE_POSITION - AGGRESSIVEDOWNTOLERANCE))
    .withCondition("LabelNames CONTAINS_ANY ['Generic']")
    .withCondition("Cost" / "ConvertedClicks > 5") // problem is here
    .orderBy("AveragePosition ASC")
    .forDateRange("LAST_7_DAYS")
    .get();

  while (CCIncrease.hasNext()) {
    var keyword = CCIncrease.next();
   
    if( (keyword.getCost() / keyword.getconvertedClicks()) > 25)
    {
    keyword.setMaxCpc(keyword.getMaxCpc() * BID_ADJUSTMENT_COEFFICIENT);
    }
    else
    {
    }
  }
}

 

 

Thanks

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author rashed k
September 2015

Re: Cost/Conversions bidding script problem

Top Contributor
# 3
Top Contributor

Hi rashed, one more thing...

 

The keyword object doesn't actually contain cost or convertedclicks data, so in your while loop you'll need the line:

 

var kStats = keyword.getStatsFor("LAST_7_DAYS");

 

then your conditional statements will need to reference kStats.getCost() and kStats.getConvertedClicks()

 

Jon

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

View solution in original post

Re: Cost/Conversions bidding script problem

Top Contributor
# 2
Top Contributor

Hi rashed, no laughing here, adapting an existing script is an excellent way to learn and there are no silly questions so feel free to ask anything.

 

In this case the problem is that Conditions can't accept calculations - they can only be valid columns within the object.  In other words you can have a condition that queries Cost, and you can have a condition that queries ConvertedClicks, but you can't have a condition that queries a formula based on those two.

 

The only solution is to do your selection using one condition then perform another test in the while loop to check the actual cost/convertedclicks figure.  I'd probably replace your line with these two:

 

.withCondition("Cost > 0")

.withCondition("ConvertedClicks > 0")

 

Yes, I know anything with a conversion should have a cost, but it's better to be safe.

 

Then just if conditions as you already have to test the actual formula and act upon it.

 

As an aside, when you may end up with lots of tests, you might want to look at using select...case instead of if.. else.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits
Marked as Best Answer.
Solution
Accepted by topic author rashed k
September 2015

Re: Cost/Conversions bidding script problem

Top Contributor
# 3
Top Contributor

Hi rashed, one more thing...

 

The keyword object doesn't actually contain cost or convertedclicks data, so in your while loop you'll need the line:

 

var kStats = keyword.getStatsFor("LAST_7_DAYS");

 

then your conditional statements will need to reference kStats.getCost() and kStats.getConvertedClicks()

 

Jon

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

Re: Cost/Conversions bidding script problem

Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆
Aha!! Cool thanks. I was just about to ask about the problem in the loop. I'll add this in and get back to you. I've also added in the condition for the cost. Thanks Jon Smiley Happy

Re: Cost/Conversions bidding script problem

Follower ✭ ☆ ☆
# 5
Follower ✭ ☆ ☆
It's worked. Thanks Jon Smiley Happy

Just in case somebody else has this problem, here's what I did:

while (CCIncrease.hasNext()) {
var keyword = CCIncrease.next();

var kStats = keyword.getStatsFor("LAST_7_DAYS");


if( (kStats.getCost() / kStats.getConvertedClicks()) > 2)
{
keyword.setMaxCpc(keyword.getMaxCpc() * BID_ADJUSTMENT_COEFFICIENT);
}
else
{
}