AdWords
4.8K members online now
4.8K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

SCRIPTING - keyword.getAveragePosition()

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi

-

In the list of useful data that the keyword class returns, I was hoping I could use something like this

keyword.getAveragePosition() but it appears to be missing, any ideas anyone?

https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_keyword

-

cheers

Tom

1 Expert replyverified_user

Re: SCRIPTING - keyword.getAveragePosition()

Top Contributor
# 2
Top Contributor

Hi again Ross.  The getAveragePosition method can only be called for an object containing statistics for a given date range so, for a Keyword, you need to take three steps.

 

1)  Use a selector to obtain a Keyword iterator, e.g.

 

var myKeywords = AdWordsApp.keywords().get();

 

(you'll probably want to add some conditions to this iterator)

 

2)  Check for each keyword in the iterator and create a single keyword object, then call stats for that Keyword:

 

while (myKeywords.hasNext()) {

  var thisKeyword = myKeywords.next();

  var thisStats = thisKeyword.getStatsFor("LAST_7_DAYS");

}

 

3)  Retrieve the average position from the stats

 

var thisPosition = thisStats.getAveragePosition();

 

You'll probably want to use some other variables to store the results for each of the Keywords in an array of some kind but this should get you going...

 

Jon

 

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

Re: SCRIPTING - keyword.getAveragePosition()

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
wow thanks again for your help Jon
works perfectly, and makes logical sense now I think of it.
Tom