Alexa is a great tool for gathering your website’s statistics. Using its traffic rank moving average, you can see how your content affects your site’s popularity over time.
Unfortunately Alexa does not provide detailed history data for sites outside the top 100,000. This makes it slightly more difficult for people running smaller sites to track their trends. Fortunately, we can create a simple script that screen-scrape the traffic ranking information from the HTTP response.
The following shell script illustrates a simple script to parse the traffic ranking information:
#! /bin/sh wget -SO- http://www.alexa.com/siteinfo/{site url} 2>&1 | grep -i "alexa traffic rank" | sed -e 's/.*is ranked number //g' | sed -e 's/in the world according.*//g' | sed -e 's/,//g' | grep '^[0-9]*' -o >> {log file name}
Note that the wget statement should be kept in a single line. It is broken into multiple lines for legibility.
One challenge is that the returned verbiage changes according to the rough rankings of the sites so you may have to play around with the HTML a little bit to get the parsing working properly for your particular site. But for any given site, the returned HTML should be relatively stable.
If you run the above script as a scheduled job (e.g. through cron), then you will be able to chart your own traffic trend over time.