[Piwik-svn] r353 - trunk/misc

svnmaster at piwik.org svnmaster at piwik.org
Mon Mar 10 19:02:17 CET 2008


Author: matt
Date: 2008-03-10 19:02:17 +0100 (Mon, 10 Mar 2008)
New Revision: 353

Added:
   trunk/misc/api_example_marketing.php
Log:
- adding new tutorial, using Piwik API

Added: trunk/misc/api_example_marketing.php
===================================================================
--- trunk/misc/api_example_marketing.php	                        (rev 0)
+++ trunk/misc/api_example_marketing.php	2008-03-10 18:02:17 UTC (rev 353)
@@ -0,0 +1,26 @@
+<h1>Ratio of visitors that try the Piwik online demo</h1>
+<p>This report is automatically computed in PHP using the <a href='http://dev.piwik.org/trac/wiki/API/Reference'>Piwik APIs</a>. In 10 lines of PHP you can get the data and generate this kind of report.
+</p><p>This report is generated in order to see how <a href='http://piwik.org'>Piwik.org</a> visitors are interested in Piwik, which we determine by the ratio of visitors that look the <a href='http://piwik.org/demo'>online demo</a>.</p>
+<?php
+$visitsDemo = file_get_contents('http://piwik.org/demo/?module=API&method=Actions.getActions&idSite=1&period=day&date=last7&format=php&filter_column=label&filter_pattern=demo');
+$visitsAll = file_get_contents('http://piwik.org/demo/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=1&period=day&date=last7&format=php');
+
+$visitsDemo = unserialize($visitsDemo);
+$visitsAll = unserialize($visitsAll);
+
+$ratioSum = $count = 0;
+
+print('<table border=1 cellpadding=4><thead><td>Date</td><td>Nb visits</td><td>Nb visits on /demo</td><td>Ratio</td></thead>');
+foreach($visitsDemo as $date => $values)
+{
+	$nbVisitsDemo = $values[0]['nb_visits'];
+	$nbVisits = $visitsAll[$date];
+	$ratio = round($nbVisitsDemo * 100 / $nbVisits, 0);
+	$ratioSum += $ratio; $count++;
+	
+	print("<tr><td>$date</td><td>$nbVisits</td><td>$nbVisitsDemo</td><td>$ratio %</td></tr>");
+}
+print('</table>');
+
+$averageRatio = round($ratioSum / $count, 0);
+print("<p><b>Average visitors visiting the online demo = $averageRatio %</b></p>");



More information about the Piwik-svn mailing list