The main feedback we had after the last API announcement was that people wanted to be able to retrieve more detailed information, particularly information on recent visitors. We also were asked questions about how features might be achieved, such as a Google Maps mashup or show most popular links, etc. Our aim for this release of the API was to add additional functions that hopefully meet those needs while also being a jumping off point for many other cool ideas.
We would love to hear from you if you do produce something with our Metrics API, you might get your moment of fame on the Performancing homepage plus we have a page in the handbook to promote your Metrics services, blog plugins and tools.
As always, refer to the API handbook for reference but now I will go through the new functions and what they do.
New API Functions
- getgeodetails – Returns which countries your visitors are coming from and their percentage of total, eg. USA: 65%
- getpagedetails – Returns detailed information for a specified URL, such as views, clicked links, referrers, comments etc
- getvisitordetails – Returns detailed information for visitors such as IP, language, browser, resolution, etc plus the pages they visited
Do have a play with these new functions, particularly the last two are very powerful as you will see when you start using them. I’m sure you will be able to think of some very interesting applications for them …
There are also two changes that have been made
- You do not need to go through the Auth process if the blog is setup in Metrics to have public stats
- Many functions that return repeated rows now have a “Limit” parameter that allows you to limit how many rows are returned
Example Code
The following example returns a list of the most popular links for a particular page of your blog.
“, ““))
{
if(!strstr(GetElementByName($node, “
$data = substr($data, $pos);
}
/*
** sort the array
*/
arsort($links);
/*
** output the array as a list
*/
foreach($links as $name=>$value)
{
print “
}
/*
** function to return a specific XML element contents by name
*/
function GetElementByName(&$xml, $start, $end) {
global $pos;
$startpos = strpos($xml, $start);
if ($startpos === FALSE) {
return FALSE;
}
$endpos = strpos($xml, $end);
$endpos = $endpos + strlen($end);
$pos = $endpos;
$endpos = $endpos – $startpos;
$endpos = $endpos – strlen($end);
$tag = substr($xml, $startpos, $endpos);
$tag = substr($tag, strlen($start));
return $tag;
}
?>
First we set the start and end dates, domain, url and how many links we want returning. With that information we can go to the API and grab our XML.
The information we want is embedded in a series of “Link” tags, we want the “URL” and “Clicks” data and place them in an array. To get at these specific pieces of information I use a function called GetElementByName. If you wanted to display everything returned from the XML you might find it more efficient to just process it as you read it.
Once we have our array we can sort it, my preference is for descending, and loop through the array either processing it or in the above example just output it straight to the user.
Over to you!
Already you have produced some great apps, modules and plugins, as I say above, our hope is that you will take these functions and really surprise us all.
powered by performancing firefox