Skip to content

Instantly share code, notes, and snippets.

@sashtown
Created July 25, 2013 16:25
Show Gist options
  • Save sashtown/6081392 to your computer and use it in GitHub Desktop.
Save sashtown/6081392 to your computer and use it in GitHub Desktop.
Piwik stats: Display unique visitors
<?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 = 'your_fancy_piwik_token';
$url = "http://stats.your-domain.com/";
$url .= "?module=API&method=VisitsSummary.getUniqueVisitors";
$url .= "&idSite=1&period=week&date=today";
$url .= "&format=PHP";
$url .= "&token_auth=$token_auth";
$fetched = file_get_contents($url);
// More stuff: http://piwik.org/docs/analytics-api/reference/
?>
<!-- Display stats -->
<p><?php echo unserialize($fetched); ?> unique visitors this week.</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment