Show only 1 graph to public

Hi all,

I only want to show the summary graph (“Last visits graph”) to the public on my webpage. Is this possible? Users should not be able to see all stats, only this graph!


Hm, searching around in the forum shows that there are several requests for this feature, and I also found the feature request here: Ticket 283 . Unfortunately it’s already more than 2 years old :sunglasses: so it does not seem to be an easy solution, and the last change was 5 months ago and the priortiy has been downgraded… so it does not seem to be possible now, and it’s probably not coming in the near future. :S Bad, Bad, because Piwik is really fine but showing the traffic also to my visitors is quite important for me… so it seems have it to search around again (even though something brillant like Piwik is nearly impossible to find again…)

That long, eh? Yes, we haven’t made this a priority. I think changes to the login authentication, and introducing openid and oauth will come before fine-grained permissions to widgets.

I’m surprised. I thought that most people having such counters also would like to show it to their users… I mean the stats is of course also nice for me, but at least the daily counter might be interested for others… And I thought it should not be too complicated: The data is already available, so I “only” need a widget which displays only this graphics. But as often, it’s not as easy as it seems to.

Hey! I think this might help you. I put it together in PHP, and so you can just add it to your page if it is in PHP, or include it in an iframe if you don’t want to deal with it.

You need access to the database Piwik is installed on for this (I find it faster than the API). I wrote this this morning, and I have only had Piwik installed for 2 weeks now, so I had a limited dataset to test this on. Let me know if you find any bugs or want it to do anything else!

By default it prints out the lifetime total visits in a

and then uses the Google charts API to display a weekly visit chart.

Hope this helps!

/** Simple script to display specific statistics to users
 *  this requires access to the database which Piwik is installed
 * @author        Dustin B < >
 * @license       GPL
 //     Settings          //
 # $site_id is the Piwik ID for the site you want stats on
 # If you don't know it, you can find it in the javascript tracking tag
 $site_id = "2";
 # $start_date is how far back you want data from, in the format YYYY-MM-DD 
 $start_date = "2010-12-01";
 # How wide  & tall you want the visits chart to be (in pixels)
 $chart_width = "250";
 $chart_height = "150";
 # Database Piwik is stored on
 $db["host"] = "localhost";
 $db["user"] = "";
 $db["pass"] = "";
 $db["name"] = ""; 
 //     Script              //
 # Connect to db
 $db = new mysqli($db["host"], $db["user"], $db["pass"], $db["name"]); 
 # First get all time total visitors
 # For users who want a "counter" displayed
  $stmt = $db->query("   SELECT COUNT(idvisit) as visits
                        FROM piwik_log_visit 
                        WHERE idsite=$site_id
                        ORDER BY idvisit" );
 $ttl = $stmt->fetch_array();
 $stmt = $db->query("   SELECT COUNT(idvisit) as visits, visit_server_date as date 
                        FROM piwik_log_visit 
                        WHERE idsite=$site_id AND visit_server_date >=$start_date 
                        GROUP BY visit_server_date 
                        ORDER BY idvisit" );
 while($daily = $stmt->fetch_array())
    # Find the week of the year to group visits by for graphing
    # Also include the year to prevent overlaping if start_date is over 1 year ago.
    $timestamp = strtotime($daily["date"]);
    $week = date("W Y", $timestamp);
    # Find date range to display on chart
    $day_of_week = date("N", $timestamp);
    # If it's not monday, find most recent money (which is when the week started) for label
    if($day_of_week !== 1)
        $step_back = $day_of_week - 1;
        $label = date("M j", strtotime("-$step_back days", $timestamp));
        $label = date("M j", $timestamp);
    $wkly[$week]["visits"] += $daily["visits"];
    $wkly[$week]["label"] = $label;
    $visit_array[$label] += $daily["visits"];
 foreach ($wkly as $week)
    $chart["data"] .= $week["visits"].",";
    $chart["label"] .= "|".$week["label"]; 
 $chart["data"] = substr($chart["data"], 0, -1);
 $chart_max = max($visit_array) * 1.15;
 $chart_min = min($visit_array) * .85;
 echo "<h3>Total Visitors: ".$ttl["visits"]."</h3>";
 echo "<img src='".$chart_width."x".$chart_height."&chd=t:".$chart["data"]."&chxt=x,y&chds=".$chart_min.",".$chart_max."&chxr=1,".$chart_min.",".$chart_max."&chxl=0:".$chart["label"]."|'/>";