Blogging

Blog Metrics API 2.0 Released!

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

  1. You do not need to go through the Auth process if the blog is setup in Metrics to have public stats
  2. 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, ““),$domain)) $links[GetElementByName($node, ““)] = intval(GetElementByName($node, ““, ““));
$data = substr($data, $pos);
}

/*
** sort the array
*/
arsort($links);

/*
** output the array as a list
*/
foreach($links as $name=>$value)
{
print “

  • $name #$value”;
    }

    /*
    ** 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

    Author: Chris Garrett

    Chris Garrett is a content marketing and blogging coach and co-author of the Problogger Book with Darren Rowse.

  • 8 thoughts on “Blog Metrics API 2.0 Released!

    1. Um…maybe? I’d have to play around with Textpattern first, but I’ll see if I can put it on the to-do list…

    2. Come on Dave, you could easily write a Textpattern plug-in couldn’t you?

    3. Well it still sounds like a good idea for the WP plugin anyway, so thanks for the inspiration! 😉

    4. @Dave: I want that in the ‘my metrics’ browser interface 🙂

      No WP around to install your nice plug-in.

    5. Thanks for these API improvements Chris! I’ve finally got a day off from work tomorrow and I plan on putting some major work into the 0.4 version of the WordPress plugin. Markus, your idea about having metrics details on the post page is a good one and I’m putting it in the feature request list!

    6. Most interesting for me:

      “detailed information for a specified URL”

      I would love to click on a post in the posts table and be able to see the PMetrics overview instead of the page.

      “the pages the vistor visited”

      Following the visitors route on internal and external links would be nice. I think of a visitor table and you click on the visitor and get the overview.

      A visitor detail which seems to be missing are the returned visits with date and time.

      Another feature we have been discussing about in the forum:

      Splitting the referrers into SE and Non-SE referrer pages. For the SE referrer page I would love to have a graph like the visitor graph to see how the SE referrers (only the SE domains) develop.

      Other relations I’d like to have:

      The percentage ratio SE versus normal PI (i.e. 85% SE / 15% PI)
      The URL PI versus AdSense clicks. Of course only for URLs which received an AdSense click in the date range. (i.e. URL 850 PI / 2 AS clicks)

    7. You already see visitor details, we might extend how many you see at once. We have been thinking over ideas for the rest …

      • 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

      Will those functions be implemented into the ‘my metrics’ GUI?

    Comments are closed.