API Request Actions→Pages→Pageviews


(piclone) #1

Hi Forum!
I found the following code for a total counter in your sidebar:

define('PIWIK_ENABLE_SESSION_START', 0);
	define('PIWIK_INCLUDE_PATH', $_SERVER['DOCUMENT_ROOT'].'/piwik');
	define('PIWIK_ENABLE_DISPATCH', false);
	define('PIWIK_ENABLE_ERROR_HANDLER', false);
	require_once PIWIK_INCLUDE_PATH . "/index.php";
	require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
	
	Piwik_FrontController::getInstance()->init();
	
	$token = 'my_token';
	$start = '2008-01-01'; // use the earliest date in your database
	$today = date('Y-m-d');
	$request = new Piwik_API_Request('
	method=VisitsSummary.get
	&idSite=1
	&date='.$start.'%2c'.$today.'
	&period=day
	&format=PHP
	&serialize=0
	&token_auth='.$token.'
	');
	$result = $request->process();
	
	$total = 0;
	foreach ($result as $index => $val) {
	@$total = $total + $val['nb_visits'];
	}
	
	return "$total";

It works quite well but I’d like to have something else now. As this is displayed in a sidebar like column on each site I want that it shows only the number of pageviews on this site (e.g. on /index.php 42 visitors and on /index.php?site=contents&siteid=1 15 visitors). So it’s just the same thing as you can find in the piwik center under
Actions→Pages→Pageviews.
I looked it up in your (api-)Docs but I’m either to stupid or there’s really no helpfile about it.
And so before I start looking at the code of the Action-Pages-Menu I thought you could help me finding a solution.

Thanks!