How to Get Stats & Charts from Alexa (Part 1)

by on June 21, 2011

Alexa is a very popular and free service for ranking website traffic. They compute traffic statistics by analyzing the web usage of millions of browsers which have installed their proprietary add-ons and plug-ins. The most well-known of these is the Alexa Toolbar.

But to webmasters and bloggers, Alexa's ranked measurements can be an important element in leveraging our site's popularity as a selling point to advertisers, sponsors, buyers, and readers. Plus, because their data is readily open to public review, the status of top ranks and/or climbing trends is a coveted (and often competitive) objective.

The lower the Alexa ranking number, the more heavily visited the site. Some current examples are: Google (1), Facebook (2), YouTube (3) … Wikipedia (7) … Twitter (9) … Amazon (17), and WordPress.COM (18). As with lower traffic sites, these top positions are constantly shifting.

In this article series, we'll start by discussing basic background information. Then, we'll develop PHP functions and WordPress shortcodes which gather data and images using undocumented Alexa services. You can easily present these numerous statistics and various charts on your own site, publicly or privately. Please note that attribution MUST be given to Alexa for the data presented, preferably with at least one link.

Advanced developers may want to skip ahead to grab these functions … 700+ lines of source code. In this article series, we'll explain it all … revealing, along the way, both coding tricks and undocumented Alexa access secrets. The easiest implementation is to put the collection in your theme's functions.php file (within php tags).

Table of Contents for this Article Series
    Toggle Article Details

  1. Introduction: Alexa Data Overview  (you are here)
  2. (coming soon) How to Get Stats & Charts from Alexa (Part 2)
  3. (coming soon) How to Get Stats & Charts from Alexa (Part 3)
  4. (coming soon) How to Get Stats & Charts from Alexa (Part 4)

A Breif Overview of Alexa

Founded in 1996, Alexa Internet, Inc.  is a California-based subsidiary company of (acquired in 1999). Their name was chosen in homage to the ancient Library of Alexandria … drawing a parallel between the largest repository of knowledge in the ancient world to the modern-day, tantamount potential of the Internet.

In addition to collecting traffic data with their browser add-ons, they also crawl virtually every site on the web archiving pages in their ever-expanding database. Currently, with more than 100 terabytes and 10 billion web pages archived from 1996 to the present (using their ia_archiver webbot), their donated data serves as the basis for the Wayback Machine which lets users view historical snapshots of most the Internet.

Alexa generates revenue from advertising and SEO Site Audits. They also offer two very low cost data feed services: Alexa Top Sites and Alexa Web Information Service. The techniques that we use in our code are a free, but currently undocumented  subset of the extensive AWIS programming service.

Alexa Traffic Data Collection

Alexa is sort of like the Internet's version the Nielsen Ratings (which tracks the popularity of TV shows). And in a manner similar to the Nielsen Ratings, Alexa's ratings analyze measurements of the browsing traffic patterns of a representative number of people online (estimated to be 10-million+) and project those numbers to the whole internet.

Also, it is worth noting that Alexa specifically states they not attempt to analyze web usage data to determine the identity of any user. You can peruse their Privacy Policy here.

Because Alexa's add-ons (which measure the traffic patterns) tend to be installed in the browsers of tech-oriented surfers, such as bloggers and webmasters, the raw data samples are clearly skewed. However, the service does utilize data-normalization strategies to compensate for this differential. You may be interested in reading their own Traffic Stats FAQ and Traffic Rankings Explanation.

Add-ons Available from Alexa

With this information in mind, it's a very good idea to install their toolbar add-on for your browser. This way your own traffic on your site will be included. It's available for Chrome, Internet Explorer (M$IE), and Firefox … on Linux, Mac, and Windows desktop operating systems.

Their toolbar specifically for Google Chrome is actually a small popup window. It's activated by clicking their icon at the top-right of the browser.

In April of this year, Alexa added a custom Toolbar Creator. It's currently available for Firefox and M$ Internet Explorer. With this utility you can not only create a custom toolbar for your own usage; but, you can also offer it to your site's visitors. Using your own content and branding, visitors will have easy access to the links you provide. Introducing the Alexa Toolbar and Toolbar Creator FAQ provide more details.

As a matter of fact, we created our own toolbar. That's a link to it own the right … click the link to check it out. We have it packed with numerous useful links for web developers. Install it for a few days to see it improves your developer-centered web surfing. If not, simply uninstall it. But, I'm betting that you will enjoy the convenience of all the carefully organized web-dev links. Topics include links for:

  • all major online email services
  • the top 15 social media sites
  • the six key links for Google services
  • web statistics sites
  • the primary developer sections
  • developer references for CSS, CSS5, jQuery, PHP, and more
  • and, an assortment of online developer tools

So … whatcha wait'n for … go get it. The link automatically opens in a new browser tab.

As with virtually all toolbars, the offering from Alexa is inserted at the top of your browser. They have a low-profile, second option for Firefox users that resides in the statusbar … Alexa Sparky.

Alexa also has some widgets that you might want to include in your sidebar. I read recently that using their traffic badges log all of your visitors as if they were using the Alexa toolbar in their own browser. But, I seriously doubt this to be factual as it would obviously skew data collection toward your site and thereby invalidate their service. Nonetheless, I've installed a traffic badge myself just to see if it does make any difference.

Alexa Registration Benefits

It's also a good idea to register with the Alexa service. As an alternative, you can also login with your Facebook account. Once you do this, you can edit some basic information for your site including contact details, site title, and site description.

Plus, after registration, you can claim your site. It may take a few days for a new site to be listed, but this can certainly expedite your inclusion in their database.

Let's Look at a Sample of Data from our Shortcode

Now that we've covered the basic background information, let's get started with our PHP functions and WordPress shortcodes.

Global Rank: 0
Page Views Daily: 1
Page Views Monthly: 30
Reviews Average: 0.0
Number of Reviews: 0
Help Us: Write a Review
Estimated Daily Earnings: 0.00
Estimated Mthly Earnings: 0.00
Estimated Site Worth: 0.01
Site Title: WP Code Snippets
Language: English
IP Address:
Host Name:
Global Traffic Rank Trend
Daily Reach (percent)
Daily Pageviews (percent)

The live  data to the right is a quick usage example … it took five minutes to create this one. The really cool aspect is that you can arrange any piece of data any way you want and apply your own style preferences. Our example in the next article in this series demonstrates many more of the data elements that you can choose from.

Notice that we made a direct link out of our Global Rank.   You can do this with any of the scraped data. Likewise, we created a Write a Review link. BTW … as you can see … hinthint … we don't currently have any reviews at Alexa. So … we encourage you to help.

This week our site celebrates its three-month anniversary. In fact, I decided to code this utility after getting excited about our own rising Alexa trends.

When Alexa first listed this site in early April (about a week after our site was launched), our ranking was 26,666,708. Three months later our overall rank is 146,788 and we're trending in the 85K range. Not bad for three months … plus, I recently installed our own custom Alexa toolbar. Maybe this will help too.

We actually have five distinct shortcodes. [wcs_alexa_data] provides most of the collected data as individual mix-n-match elements.

[wcs_alexa_chart] displays any of 7 different charts each with various options, such as size, data range, and background color.

[wcs_alexa_favicon_image] simply inserts an HTML tag for the Alexa icon. [wcs_alexa_link] encloses any included content within a link to the Alexa rank page for the specified site. And, [wcs_alexa_review_link] works the same way, except that it wraps the content with a link to the Alexa review page for the specified site.

Here's the actual HTML for this quick sample:

Code: HTMLShortcode Example HTML

<table cellpadding="0" cellspacing="0" style="font-size:12px; border:1px solid #A0A0A0; padding:8px; background:#FFFFE8; -moz-border-radius:6px; -webkit-border-radius:6px; border-radius:6px; -moz-box-shadow:1px 1px 15px #C0C0C0; -webkit-box-shadow:1px 1px 15px #C0C0C0; box-shadow:1px 1px 15px #C0C0C0;">
        <td width="300" colspan="2" align="center" valign="top" style="padding-bottom:2px; font-size:16px; border-bottom:1px solid #A0A0A0;">[wcs_alexa site= data=favicon_image] [wcs_alexa site= data=alexa_link] [wcs_alexa_favicon_image]</td>
        <td width="150" style="padding-top:10px;">Global Rank:</td>
        <td width="150" align="right" style="padding-top:10px;">[wcs_alexa_link site=][wcs_alexa site= data=global_rank][/wcs_alexa_link]</td>
        <td width="150">Page Views Daily:</td>
        <td width="150" align="right">[wcs_alexa site= data=pageviews_daily]</td>
        <td width="150" style="padding-bottom:10px;">Page Views Monthly:</td>
        <td width="150" align="right" style="padding-bottom:10px;">[wcs_alexa site= data=pageviews_monthly]</td>
        <td width="150">Reviews Average:</td>
        <td width="150" align="right">[wcs_alexa site= data=reviews_avg]</td>
        <td width="150">Number of Reviews:</td>
        <td width="150" align="right">[wcs_alexa site= data=reviews_count]</td>
        <td width="150" style="padding-bottom:10px;">Help Us:</td>
        <td width="150" align="right" style="padding-bottom:10px;">[wcs_alexa_review_link site=]Write a Review[/wcs_alexa_review_link]</td>
        <td width="150">Site Title:</td>
        <td width="150" align="right">[wcs_alexa site= data=site_title]</td>
        <td width="150">Language:</td>
        <td width="150" align="right">[wcs_alexa site= data=language]</td>
        <td width="150">IP Address:</td>
        <td width="150" align="right">[wcs_alexa site= data=ip]</td>
        <td width="150" style="padding-bottom:10px;">Host Name:</td>
        <td width="150" align="right" style="padding-bottom:10px;">[wcs_alexa site= data=host_name]</td>
        <td width="300" colspan="2" align="center"><span style="padding-bottom:5px; font-size:12px;">Global Traffic Rank Trend</span>
[wcs_alexa_chart site= type=t width=240 height=160 bkg_color=#E8F0F4 style='margin-bottom:15px; border:1px solid #A0A0A0; padding=4px; -moz-box-shadow:1px 1px 10px #C0C0C0; -webkit-box-shadow:1px 1px 10px #C0C0C0; box-shadow:1px 1px 10px #C0C0C0;']
        <td width="300" colspan="2" align="center"><span style="padding-bottom:5px; font-size:12px;">Daily Reach (percent)</span>
[wcs_alexa_chart site= type=r width=240 height=160 bkg_color=#E8F0F4 style='margin-bottom:15px; border:1px solid #A0A0A0; padding=4px; -moz-box-shadow:1px 1px 10px #C0C0C0; -webkit-box-shadow:1px 1px 10px #C0C0C0; box-shadow:1px 1px 10px #C0C0C0;']
        <td width="300" colspan="2" align="center"><span style="padding-bottom:5px; font-size:12px;">Daily Pageviews (percent)</span>
[wcs_alexa_chart site= type=p width=240 height=160 bkg_color=#E8F0F4 style='margin-bottom:15px; border:1px solid #A0A0A0; padding=4px; -moz-box-shadow:1px 1px 10px #C0C0C0; -webkit-box-shadow:1px 1px 10px #C0C0C0; box-shadow:1px 1px 10px #C0C0C0;']
        <td width="300" colspan="2" align="center">[wcs_alexa data=powered_by_image_link]


Continue Reading…

We continue in the next segment with: How to Get Stats & Charts from Alexa (Part 2).


Share This Article: “How to Get Stats & Charts from Alexa (Part 1)”

(Also Available: Press CTRL+D to Bookmark this Page)


Share Your Thoughts  3 Responses to “How to Get Stats & Charts from Alexa (Part 1)”
  1. 1

    Thank you for sharing.I love every article of all.I know more something from your website.Very good website and very interested.

  2. 2
  3. 3

    Thanks you wpcodesnippetsi setup good

Share Your Thoughts

(Some editor features are restricted unless you're logged in.)

(When replying to a specific comment, your browser may require Shift+Enter instead of just Enter.)

(get a gravatar)

Notify me of followup comments via e-mail. You can also subscribe without commenting.