by john on January 10, 2004

[UPDATE] – Version .30 released 02/08/2004

MTGoogleRank is a Movable Type plugin that allows you to programmatically determine the Google Rank of a keyword or phrase. Have a keyword that is special to you that you always want to know where you stand? MTGoogleRank is for you. MtGoogleRank uses the officially sanctioned Google API so you will be completely “street legal” in its use. To see one example of how this could be used I’ve added a simple GoogleRanks widget toward the bottom of my sidebar. I’ve also added it to my search template.

To use simply download GoogleRank.txt rename the file to and place in your Movable Type plugins directory. Then include the tag in your templates and away you go.

You need a Google API key to use this plugin. If you do not have one you can get one for free at MT has a placeholder for this key within it’s configuration. Open your administration screen, click Weblog Configuration then Preferences and about half way down the page you will find the spot for it.

MTGoogleRank includes the following tags:

MTGoogleRank – The main tag – arguments documented below.
MTGoogleRankVersion – Returns the version number of MTGoogleRank.
MTGoogleRankPoweredBy – Returns the phrase “Powered By MTGoogleRank” with a link to my site.

The main MTGoogleRank tag takes one required argument and optionally up to three additional arguments:

query = the actual query to pass to Google. This is a required argument and you will get a rebuild error if you don’t include it.
url = by default MTGoogleRank uses your own weblog’s url as defined within MT to use in the search. You can override this default if you choose.
pages = by default MTGoogleRank only searches through the first page of results in Google. You can override this default if you choose. Take caution when doing so, however, as the Google API is a little slow and scrolling through many pages is going to slow things down significantly.
count = when the count argument is included MTGoogleRank will return the total estimated number of results for the given query. When this argument exists it is assumed you want the count returned – the value you use does not matter.

MTGoogleRank returns either a numeric value representing the GoogleRank calculated or a string formatted like “>#” where # is the number of results searched. So if you passed the argument pages=3 that would actually search through the first 30 results on Google (10 results per page) and if your search string was not found the value “>30” would be returned. If the count argument is included then the numeric value returned will be equal to the estimated total result set size.

Here are some usage examples:

<MTGoogleRank query=”rubber chicken”/>
<MTGoogleRank query=”rubber chicken” url=””/>
<MTGoogleRank query=”rubber chicken” url=”” pages=”3″/>
<MTGoogleRank query=”rubber chicken” pages=”3″/>
Out of <MTGoogleRank query=”rubber chicken” count=”true”/> pages on Google, I am in position <MTGoogleRank query=”rubber chicken”/>
<MTGoogleRank query=”” count=”true”/> pages are linked to my site.

Thanks to code from Adam Kalsey MTGoogleRank also supports embedded MT tags, for example:

<MTGoogleRank query=”[MTBlogName]” url=”[MTBlogURL]” pages=”3″/>

Note that instead of using the tag as you would find it in your templates, <$MTBlogName$> you need to use [MTBlogName] with the square brackets.

In a future article I will show you how you can utilize Brad Choate’s MTMacro plugin to include MTGoogleRank results within an entry.

I hope you find it useful. I’d also love to get suggestions for improvement, there should be many.

Tip of the hat to Joe for the inspiration.


* 02/08/2004 – Version .30 released.
** Added MTGoogleRankVersion tag.
** Added MTGoogleRankPoweredBy tag.
** Added code to handle the occasional Google “burp”.
* 01/14/2004 – Version .20 released.
** Added count argument.
* 01/10/2004 – Version .10 released.
** Initial release.

Previous post:

Next post: