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

Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Looking for a simple AdWords script that will run every x hours or x days and automatically adjust keyword bids based on average position. I'm looking to keep my ads in the #2 spot and want to automate that as much as possible. I also want to be able to put an upper limit on the bid so I don't get too crazy on the spend.

2 Expert replyverified_user
6 ACCEPTED SOLUTIONS

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by Theresa_Zook (Rising Star)
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Top Contributor
# 8
Top Contributor

Hi Patrick,

 

I use a script like this in many of my Accounts and the easiest solution to the problem of specifying which Campaigns to work upon is to use Labels.  Scripts can test for the existence of certain Labels (or one in a Set of Labels) so it's possible to restrict the action of the script to only those Campaigns you specify by using the condition:

 

.withCondition("LabelNames CONTAINS_ANY ['yourlabel''])

 

For my use, I make bid adjustments based upon the average position over the past 7 days and "Yesterday".  I developed the use of both these ranges to overcome the problem of "over-promoting" a Keyword.  For example, say a Keyword has an average position of #3 for the past 7 days and the script increases it's CPC on Day 1.  On Day 2, it's 7-day average is probably still going to be #3, so the script increases the bid again.  Depending upon the actual bid, and the percentage increase you apply, it's possible that you could apply an increase based upon the 7-day average when in fact the bid is now sufficient to reach #2 on a daily basis, so my script looks at both the 7-day average and "Yesterday", weighting the results of yesterday heavily to try and avoid this.

 

It's also a good idea to use Ad Scheduling and appropriate bid adjustments to compensate for hours of the day when the position changes (given enough data).  For example, your 7-day average might be #2, but you may find that for the hours between 8am and 10am, it's #1.5 and between 4pm and 7pm it's #2.9, so you could use scheduling and bid modifiers to overcome this.

 

The script will take some time to "settle", particularly if you use bid modifiers, but it does work.

 

The full script is below.  PLEASE ensure you PREVIEW the script before running it live and check the Log output for sensible changes.  The logger will output the Keyword, it's current CPC, position and the proposed new CPC.  IF it all looks OK, then schedule the Script to run daily around 1am.

 

Jon

 

// Script to adjust Keyword positions
// (c) Jon Gritton 2014

//max CPC cap
var maxCPC = 8.00;
//min CPC
var minCPC = 0.15;
//percentage change down
var perDown = 0.98;
//percentage change up
var perUp = 1.03;
//target position
var posTarget = 2.0;

function main() {
adjustKeywords();
}

function adjustKeywords() {
var keywordIter = AdWordsApp.keywords()
//.withCondition("CampaignName CONTAINS 'yourtext'") //use this to identify Campaigns
.withCondition("CampaignStatus = 'ENABLED'")
.withCondition("AdGroupStatus = 'ENABLED'")
.withCondition("Status = 'ENABLED'")
//.withCondition("LabelNames CONTAINS_ANY ['yourlabel']") //use if you've applied a Label to Keywords
.forDateRange("LAST_7_DAYS")
.orderBy("Clicks DESC") //ensures good coverage if there's a danger the script will time out
.get();

while (keywordIter.hasNext()) {
var thisKeyword = keywordIter.next();
// Check stats for both last 7 and Yesterday
var statsSeven = thisKeyword.getStatsFor("LAST_7_DAYS");
var kPosSeven=statsSeven.getAveragePosition();
var statsYest = thisKeyword.getStatsFor("YESTERDAY");
var kPosYest=statsYest.getAveragePosition();

if(kPosSeven != 0) { //don't change bids for Keywords without impressions

// If there is no position for yesterday, use last 7, if there is, use
// a calculated average weighted in favour of yesterday. This should
// prevent continued bid changes when previous changes in recent days
// have already had the desired effect.
var kPosFull = (kPosYest == 0) ? kPosSeven : (kPosSeven + (kPosYest * 2))/3;
var kPos = kPosFull.toFixed(2); //set to two decimal places, just for clarity in logging

var currCPC = thisKeyword.getMaxCpc();
var newCPC = currCPC; //just set so newCPC always has a default value;

//Rules - here you can apply your own rules to adjust CPC
//these are very simple

if(kPos > posTarget) {
newCPC = currCPC * perUp;
}

if(kPos < posTarget) {
newCPC = currCPC * perDown;
}

//we always want CPC above lower limit and below upper limit
if(newCPC < minCPC) {newCPC = minCPC;}
if(newCPC > maxCPC) {newCPC = maxCPC;}

newCPC = newCPC.toFixed(2);

Logger.log("KW: " + thisKeyword.getText() + ", CurrCPC: " + currCPC + ", NewCPC: " + newCPC + ", KPos: " + kPos);
thisKeyword.setMaxCpc(newCPC);
}
}
}

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

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Patrick Healy
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Participant ✭ ✭ ☆
# 9
Participant ✭ ✭ ☆
Hey Patrick,

If I were you, I would use those two rules and add a third. However, I would set them up by going to the keyword tab, looking at all keywords from all campaigns and then I would filter out the two campaigns that you didn't want to follow the same rules.

From there, I would modify the existing rules to exclude paused keywords.

My rules would look like this:
1) If the average position of the keyword is better than 1.25 and the keyword is active and above the first page bid then lower it by 5%
2) if the average position of the keyword is worse than 3 or 4 and the keyword is active and above the first page bid then raise it by 20%
3) If the keyword is active but below the first page bid then raise it by ___ %

The reason that I subtracted keyword below the first page bid from 1 & 2 is that sometimes a keyword can show as both a high position and below the first page bid. Your rules would be conflicting against each other if you don't exclude it from the earlier rules.

Also, I'm curious as to what your account goals are? Typically if I set up rules, I would put emphasis on CPA and conversion volume. Just curious if those are a factor in your goals or if it is purely impression-oriented in attempt to increase exposure?

View solution in original post

Marked as Best Answer.
Solution
Accepted by Theresa_Zook (Rising Star)
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Top Contributor
# 12
Top Contributor

Hi Patrick,

 

The problem with using Labels at the Campaign level is that you'd need to use a Campaign selector, which makes things slightly less elegant because you'd have to iterate through the Campaigns then through the Keywords in a nested loop.  The script at the moment jumps straight to the Keyword selector, so it can check for Labels at the Keyword level (using the LabelNames column in the line you copied) but it can't check for Labels at the Campaign level, because that's not an available column for testing for Keywords.  The only option using this method is to have a specific naming convention for your Campaign names, then look for a string or part of.  This is shown in the line:

 

//.withCondition("CampaignName CONTAINS 'yourtext'") //use this to identify Campaigns

 

You can check for Labels at the Campaign level, but you need to then use a nested loop, as follows.  Alter the adjustKeywords function to put this at the start, as follows:

 

function adjustKeywords() {

var campaigns = AdWordsApp.campaigns()

  .withCondition("Status = 'ENABLED'")

  .withCondition("LabelNames CONTAINS_ANY ['yourlabel']")

  .get();

 

while(campaigns.hasNext()) {

  var thisCampaign = campaigns.next();

 

Then amend the first few lines of the existing keyword selector to read:

 

var keywordIter = thisCampaign.keywords()
.withCondition("AdGroupStatus = 'ENABLED'")
.withCondition("Status = 'ENABLED'")
.forDateRange("LAST_7_DAYS")
.orderBy("Clicks DESC") //ensures good coverage if there's a danger the script will time out
.get();

 

Then add an extra closing } at the end of the function (for the campaign iterator while loop).

 

That should do it, but, as before, Preview endlessly before applying.  If it doesn't work, get back to me tomorrow and I'll test it - I've written this on the fly...

 

Just so you know, what this now does is first select all the Campaigns with the label you're using, then it iterates these Campaigns and selects all their Keywords.

 

Jon

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

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Patrick Healy
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Participant ✭ ✭ ☆
# 13
Participant ✭ ✭ ☆

Hey Patrick,

 

That makes sense, I was just curious! The "below first page bid" is sort of sneakily hidden away. You can target it by adding status as a qualifier in the rule. Once you add status, you can uncheck everything except for "below first page bid" (or to exclude BFPB, you can check everything BUT that). It's within the "eligible - limited" section of status, the same way it is if you add a filter on the keyword tab.

 

 

setting_a_rule.png

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Patrick Healy
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 16
Visitor ✭ ✭ ✭
Hold off for a bit, Jon. I tried something that I think will work perhaps better.

I duped the script and created sightly different versions of it. All are separated by $1 on the price and refer to a unique label.

I then went through all the keywords and assigned them to the next dollar amount up (a $4.17 word is assigned to the $5 label).

Now that they have some wiggle room all I have to do is run a filter for exact even dollar amounts (i.e., $3.00) to see where they have topped out and make the decision of whether or not to promote them to the next level.

If the price drops I do nothing since it costs me less and if i don't want a word to play in this space I simply don't assign one of those varying pricing labels to it.

As a reality check I set up an automated rule to run before the scripts and bounce up the bid by 10% on any of my manually set words in the account that aren't hitting the first page due to low bid.

If that rule puts us too high for the script threshold it will get bounced down to a whole number when the script runs shortly thereafter and it will trigger me going in to take a look at it.

And that will happen before the campaign kicks in every morning so I'll minimize the bid being too high. Then again, if I'm underbidding the page one threshold at this point I've probably done that because I'm still hitting around the 2.0 slot - which is fine (I've observed, it's odd).

What do you think?

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Patrick Healy
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 19
Visitor ✭ ✭ ✭
So after about a week of running the combo of the scripts and the rule here's where I'm at:

the scripts are running well and adjusting my bids daily up and down. It's keeping me in the area that I want to be in. Those outliers that don't make the cut to page 1 are being bounced up to get them in the general area where they can start to get some impressions and clicks so the scripts come in and start to work on them getting them out of the 2nd page zone.

Now that the solution is a bit settled I can run a small handful of filters based on performance criterion and look at where I need to make improvements to get more words in that system. Out of about 650 keywords about 250 aren't getting any significant placement so now I can focus on them to either deactivate them or alter them to get them in a place where there's sufficient search traffic.

The takeaway: It looks like it's working as planned. Thank you Jon and Amy for the insights and expertise. I think I've crafted a winner with the info you both gave me. You two rock!

View solution in original post

Re: Need an AdWords Script that adjusts bids by average position

Top Contributor
# 2
Top Contributor
Hi Patrick,

I am not sure but may this is what you looking for? https://developers.google.com/adwords/scripts/docs/solutions/bid-to-position

Let us know if this doesn't solve your query.

Thanks
Neha
Neha Gupta, AdWordsTop Contributor Follow Me: My Blog | Twitter | Google+ | LinkedIn
Did you find any helpful responses or answers to your query ? If yes, please mark it as the ‘Best Answer’

Re: Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
I found this earlier today. The thing that concerns me with this script is that it will be applied to all keywords in an account correct? There are a few campaigns I don't want this applied to. Also, I want to set a maximum bid on some of these as certain campaigns contain keywords that can get awfully spendy.

Re: Need an AdWords Script that adjusts bids by average position

Participant ✭ ✭ ☆
# 4
Participant ✭ ✭ ☆
Hi Patrick,

Have you thought about using automated bidding rules instead? You could set different rules for different campaigns or groups of keyword based upon positions. You can also set maximum bid limits for each rule. You can create up to 100 different rules (not that I would suggest using that many. Smiley Happy)

Rules would also be easier to update and manage in the future, unless you have enough script experience to make adjustments as needed.

Hope this helps!
Amy

Re: Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Yeah, that's what I'm doing now - and I prefer it - but I have two rules per campaign (raise the big or lower the bid) and 10 campaigns for this one client. I can't seem to simply choose a specific set of campaigns to have one rule run with. I have to do two for each.

The problem is that I'm finding that some of my keywords are not making the cut to be on the first page so I have to go in there every day and bid those up (if reasonable). Others I am fine with not hitting the first page and taking my chances on getting that rare opportunity on. I can't get the rules to run frequent enough to make adjustments to keep some of those bids up or down. Any ideas on that?

Re: Need an AdWords Script that adjusts bids by average position

Participant ✭ ✭ ☆
# 6
Participant ✭ ✭ ☆
Interesting, thanks for the additional context! Can you tell me more about the rules you currently have in place?

Are you using a first-page bid rule? If so that might help a little. Also, if you go to the keyword tab (set on "all campaigns") you can select keywords to be included in the rule. In other words, even if they are in different campaigns, they can be managed by the same rule. This might help cut down the number of rules you have.

Re: Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
I have two rules for each campaign:
1) If the average position of the keyword is better than 1.25 then lower it by 5%
2) if the average position of the keyword is worse than 3 or 4 then raise it by 20%

I'm shooting to get these keywords to hover around the second slot. The first page rule won't do that. And since I deactivate and activate keywords somewhat regularly just selecting keywords from a filter will cause me to rewrite this rule fairly frequently. There are also 2 out of the 10 campaigns that don't adhere to these rules that I have other rules in place for them since one is buying competitors' names and the QS just sucks so I'm not bidding that up. The other is buying the client's brand so I don't want that anywhere but #1.

To compound things, these campaigns all have different max bids. Some are $4.5, some are $11 so I want to be able to control that by campaign.
Marked as Best Answer.
Solution
Accepted by Theresa_Zook (Rising Star)
September 2015

Re: Need an AdWords Script that adjusts bids by average position

Top Contributor
# 8
Top Contributor

Hi Patrick,

 

I use a script like this in many of my Accounts and the easiest solution to the problem of specifying which Campaigns to work upon is to use Labels.  Scripts can test for the existence of certain Labels (or one in a Set of Labels) so it's possible to restrict the action of the script to only those Campaigns you specify by using the condition:

 

.withCondition("LabelNames CONTAINS_ANY ['yourlabel''])

 

For my use, I make bid adjustments based upon the average position over the past 7 days and "Yesterday".  I developed the use of both these ranges to overcome the problem of "over-promoting" a Keyword.  For example, say a Keyword has an average position of #3 for the past 7 days and the script increases it's CPC on Day 1.  On Day 2, it's 7-day average is probably still going to be #3, so the script increases the bid again.  Depending upon the actual bid, and the percentage increase you apply, it's possible that you could apply an increase based upon the 7-day average when in fact the bid is now sufficient to reach #2 on a daily basis, so my script looks at both the 7-day average and "Yesterday", weighting the results of yesterday heavily to try and avoid this.

 

It's also a good idea to use Ad Scheduling and appropriate bid adjustments to compensate for hours of the day when the position changes (given enough data).  For example, your 7-day average might be #2, but you may find that for the hours between 8am and 10am, it's #1.5 and between 4pm and 7pm it's #2.9, so you could use scheduling and bid modifiers to overcome this.

 

The script will take some time to "settle", particularly if you use bid modifiers, but it does work.

 

The full script is below.  PLEASE ensure you PREVIEW the script before running it live and check the Log output for sensible changes.  The logger will output the Keyword, it's current CPC, position and the proposed new CPC.  IF it all looks OK, then schedule the Script to run daily around 1am.

 

Jon

 

// Script to adjust Keyword positions
// (c) Jon Gritton 2014

//max CPC cap
var maxCPC = 8.00;
//min CPC
var minCPC = 0.15;
//percentage change down
var perDown = 0.98;
//percentage change up
var perUp = 1.03;
//target position
var posTarget = 2.0;

function main() {
adjustKeywords();
}

function adjustKeywords() {
var keywordIter = AdWordsApp.keywords()
//.withCondition("CampaignName CONTAINS 'yourtext'") //use this to identify Campaigns
.withCondition("CampaignStatus = 'ENABLED'")
.withCondition("AdGroupStatus = 'ENABLED'")
.withCondition("Status = 'ENABLED'")
//.withCondition("LabelNames CONTAINS_ANY ['yourlabel']") //use if you've applied a Label to Keywords
.forDateRange("LAST_7_DAYS")
.orderBy("Clicks DESC") //ensures good coverage if there's a danger the script will time out
.get();

while (keywordIter.hasNext()) {
var thisKeyword = keywordIter.next();
// Check stats for both last 7 and Yesterday
var statsSeven = thisKeyword.getStatsFor("LAST_7_DAYS");
var kPosSeven=statsSeven.getAveragePosition();
var statsYest = thisKeyword.getStatsFor("YESTERDAY");
var kPosYest=statsYest.getAveragePosition();

if(kPosSeven != 0) { //don't change bids for Keywords without impressions

// If there is no position for yesterday, use last 7, if there is, use
// a calculated average weighted in favour of yesterday. This should
// prevent continued bid changes when previous changes in recent days
// have already had the desired effect.
var kPosFull = (kPosYest == 0) ? kPosSeven : (kPosSeven + (kPosYest * 2))/3;
var kPos = kPosFull.toFixed(2); //set to two decimal places, just for clarity in logging

var currCPC = thisKeyword.getMaxCpc();
var newCPC = currCPC; //just set so newCPC always has a default value;

//Rules - here you can apply your own rules to adjust CPC
//these are very simple

if(kPos > posTarget) {
newCPC = currCPC * perUp;
}

if(kPos < posTarget) {
newCPC = currCPC * perDown;
}

//we always want CPC above lower limit and below upper limit
if(newCPC < minCPC) {newCPC = minCPC;}
if(newCPC > maxCPC) {newCPC = maxCPC;}

newCPC = newCPC.toFixed(2);

Logger.log("KW: " + thisKeyword.getText() + ", CurrCPC: " + currCPC + ", NewCPC: " + newCPC + ", KPos: " + kPos);
thisKeyword.setMaxCpc(newCPC);
}
}
}

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

Re: Need an AdWords Script that adjusts bids by average position

Participant ✭ ✭ ☆
# 9
Participant ✭ ✭ ☆
Hey Patrick,

If I were you, I would use those two rules and add a third. However, I would set them up by going to the keyword tab, looking at all keywords from all campaigns and then I would filter out the two campaigns that you didn't want to follow the same rules.

From there, I would modify the existing rules to exclude paused keywords.

My rules would look like this:
1) If the average position of the keyword is better than 1.25 and the keyword is active and above the first page bid then lower it by 5%
2) if the average position of the keyword is worse than 3 or 4 and the keyword is active and above the first page bid then raise it by 20%
3) If the keyword is active but below the first page bid then raise it by ___ %

The reason that I subtracted keyword below the first page bid from 1 & 2 is that sometimes a keyword can show as both a high position and below the first page bid. Your rules would be conflicting against each other if you don't exclude it from the earlier rules.

Also, I'm curious as to what your account goals are? Typically if I set up rules, I would put emphasis on CPA and conversion volume. Just curious if those are a factor in your goals or if it is purely impression-oriented in attempt to increase exposure?

Re: Need an AdWords Script that adjusts bids by average position

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭
This client does most of their sales by phone so the goal is really to get exposure, remarketing to drive them back, and drive traffic to strategic pages. CPA, although a sexy metric, isn't practical for this client. I WISH I had a client that sold everything online. I'd be all over that. :-)

This rule structure is really nice. Thanks for this. I wasn't aware I could set a criteria for if the bid was on the first page or not. I is that a different type of rule than I am currently using? I don't see that option.