Using last visits in php


(freakystreak) #1

Hi I have an admin page which gives some simple stats such as last 10 keywords, last 10 external website referals etc all called into my php with the Piwik API. What I want to do is have the last visits graph or failing that a list of the visits to the site. Is this possible using the API? I have searched the API docs but have yet to find something that will accomplish this. The code I use to call in the API is;

<?php
    // this token is used to authenticate your API request.
// You can get the token on the API page inside your Piwik interface
$token_auth = 'anonymous';
// we call the REST API and request the 100 first keywords for the last month for the idsite=1
$url = "http:**************";
$url .= "?module=API&method=VisitsSummary.getVisits";
$url .= "&idSite=1&period=day&date=today";
$url .= "&format=PHP&filter_limit=10";
$url .= "&token_auth=$token_auth";
$fetched = file_get_contents($url);
$content = unserialize($fetched);
// case error
if(!$content)
{
    print("Error, content fetched = ".$fetched);
}
print("<h2>Visits for Today</h2>");
foreach($content as $row)
{
    $keyword = urldecode($row['label']);
    $hits = $row['nb_visits'];
    print("<b>$keyword</b> ($hits hits)<br>");
}
    ?>