Charting Amazon Sales Ranks with the Grafico
Writing a book is a long and difficult process -- one which is so laborious that most authors wonder where in the world they will find the energy to actually promote it after the writing is over! But these days it's more important than ever not only to promote new books actively, but also to gauge the success of promotional activities. Never before has the old saying "If you are not measuring it, you are not managing it" rung more true.
For many authors, one useful measuring stick is a book's Amazon sales rank (see Figure 1). A sales rank is associated with every book sold on Amazon.com; the lower the sales rank, the more popular (in terms of unit sales) the book at that given point in time. I specify "given point in time" because sales ranks are volatile, often changing daily and even hourly in accordance with sales volume fluctuations. While Amazon doesn't publish specifics regarding any information regarding the correlation between sales ranks and unit sales, publishers and authors alike have put a great deal of work into deciphering the algorithm. Many analyses are available online; however, one of my favorites is published here.
Click here for larger image
Figure 1. Amazon.com Sales Rank Associated with Every Book
Being a lazy programmer, I've never been interested in navigating to my books' various Amazon pages on a daily basis to examine the ranks. Further, charting the rank fluctuations over a long period of time can be useful for determining the efficacy of book reviews, advertising and other promotional activities. In this article, I'll focus on how I implemented the latter feature, showing you how I used the Grafico charting library to produce visual representations of sales ranks.
Incidentally, before jumping into the Grafico introduction, I just wanted to explain quickly how I'm automating the retrieval of sales ranks. I use the Amazon-ECS-PHP-Library in conjunction with Cron to execute a script every six hours (12am, 6am, 12pm, 6pm). The line in my crontab file looks like this:
0 0,6,12,18 * * * wget http://127.0.0.1/developer/2011/amazonpas/update.php -O /dev/null
The sales ranks are saved to a simple MySQL table containing each book's ASIN, sales rank, and a timestamp.
To install Grafico, head over to the Grafico website and download the
grafico.base.js file, in addition to the files representing the type of chart you'd like to create. For instance if you want to create a line chart, download the
grafico.line.js script. Once downloaded, add them to your HTML file like this (notice how I have also referenced Prototype.js via Google's CDN and Raphaël):
DIV identified by
chart defines the location where the graph will be rendered. I'll show you exactly how in the next example.
Creating a Graph
Creating a simple graph with Grafico is incredibly easy, requiring you only to identify the type of graph you'd like to create, the DIV identifying the graph location and the graph values. The following example creates the graph found in Figure 2.
Click here for larger image
Figure 2.Creating a Simple Graph with Grafico
As you can see in Figure 2, Grafico will, by default, associate each chart value with its array index offset. Presuming the chart values were inserted into the array in accordance with the day in which they were recorded, this default feature conveniently serves nicely as a chronological representation of recorded sales ranks. But there is much more we can do to improve this simple graph, starting with adding labels and adjusting the colors.
Page 1 of 2