Difference between revisions of "Piwik"

From YobiWiki
Jump to navigation Jump to search
Line 15: Line 15:
 
of the javascript code into
 
of the javascript code into
 
===Mediawiki===
 
===Mediawiki===
  +
Here is a small extension to install under extensions/Piwik/Piwik.php:
Edit the wiki page called [[MediaWiki:Common.js]] and copy/paste the Piwik Javascript code.
 
  +
<source lang=php>
  +
<?php
  +
  +
if (defined('MEDIAWIKI')) {
  +
  +
function fnPiwikHookJS($out) {
  +
global $wgPiwikURL;
  +
global $wgPiwikActionName;
  +
global $wgPiwikIdSite;
  +
$piwikcode ="\n".'<!-- Piwik -->';
  +
$piwikcode.="\n".'<a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">';
  +
$piwikcode.="\n".'<script language="javascript" src="'.$wgPiwikURL.'/piwik.js" type="text/javascript"></script>';
  +
$piwikcode.="\n".'<script type="text/javascript">';
  +
$piwikcode.="\n".'<!--';
  +
$piwikcode.="\n".'piwik_action_name = '.$wgPiwikActionName.';';
  +
$piwikcode.="\n".'piwik_idsite = '.$wgPiwikIdSite.';';
  +
$piwikcode.="\n".'piwik_url = "'.$wgPiwikURL.'/piwik.php";';
  +
$piwikcode.="\n".'piwik_log(piwik_action_name, piwik_idsite, piwik_url);';
  +
$piwikcode.="\n".'//-->';
  +
$piwikcode.="\n".'</script><object>';
  +
$piwikcode.="\n".'<noscript><p>Web analytics <img src="'.$wgPiwikURL.'/piwik.php" style="border:0" alt="piwik"/></p>';
  +
$piwikcode.="\n".'</noscript></object></a>';
  +
$piwikcode.="\n".'<!-- /Piwik -->';
  +
$piwikcode.="\n";
  +
$out->addScript($piwikcode);
  +
return true;
  +
}
  +
  +
$wgExtensionCredits['other'][] = array('name' => 'Piwik',
  +
'version' => '0.1',
  +
'author' => 'Philippe Teuwen',
  +
// 'url' => 'http://www.mediawiki.org/wiki/Extension:Piwik',
  +
'url' => 'http://wiki.yobi.be/wiki/Piwik',
  +
'description' => 'Injects Piwik JS');
  +
$wgHooks['BeforePageDisplay'][] = 'fnPiwikHookJS';
  +
}
  +
  +
?>
  +
</source>
  +
Then add the following to the bottom of your LocalSettings.php, customized according to what Piwik told you:
  +
<source lang=php>
  +
$wgPiwikURL='http://mywebsite/piwik';
  +
$wgPiwikActionName='document.title';
  +
$wgPiwikIdSite=1;
  +
require_once("$IP/extensions/Piwik/Piwik.php");
  +
</source>
  +
 
===Gallery2===
 
===Gallery2===
 
cf http://codex.gallery2.org/Gallery2:How_To_Add_Google_Analytics_to_my_Gallery_2
 
cf http://codex.gallery2.org/Gallery2:How_To_Add_Google_Analytics_to_my_Gallery_2

Revision as of 11:06, 23 April 2008

Installation

cf http://piwik.org/

apt-get install php5-gd
/etc/init.d/apache2 restart
wget http://piwik.org/last.zip

Unzip it under e.g. <your website>/piwik
And prepare a Mysq database:

mysql> create database piwik;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON piwik.* TO piwik@localhost IDENTIFIED BY 'piwikpassword';
Query OK, 0 rows affected (0.00 sec)

Now you can visit http://<your website>/piwik and follow instructions to add the first site.
For more than one site, log in and check admin/sites

Injection

of the javascript code into

Mediawiki

Here is a small extension to install under extensions/Piwik/Piwik.php:

<?php

if (defined('MEDIAWIKI')) {

function fnPiwikHookJS($out) {
    global $wgPiwikURL;
    global $wgPiwikActionName;
    global $wgPiwikIdSite;
    $piwikcode ="\n".'<!-- Piwik -->';
    $piwikcode.="\n".'<a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">';
    $piwikcode.="\n".'<script language="javascript" src="'.$wgPiwikURL.'/piwik.js" type="text/javascript"></script>';
    $piwikcode.="\n".'<script type="text/javascript">';
    $piwikcode.="\n".'<!--';
    $piwikcode.="\n".'piwik_action_name = '.$wgPiwikActionName.';';
    $piwikcode.="\n".'piwik_idsite = '.$wgPiwikIdSite.';';
    $piwikcode.="\n".'piwik_url = "'.$wgPiwikURL.'/piwik.php";';
    $piwikcode.="\n".'piwik_log(piwik_action_name, piwik_idsite, piwik_url);';
    $piwikcode.="\n".'//-->';
    $piwikcode.="\n".'</script><object>';
    $piwikcode.="\n".'<noscript><p>Web analytics <img src="'.$wgPiwikURL.'/piwik.php" style="border:0" alt="piwik"/></p>';
    $piwikcode.="\n".'</noscript></object></a>';
    $piwikcode.="\n".'<!-- /Piwik -->';
    $piwikcode.="\n";
    $out->addScript($piwikcode);
    return true;
}

$wgExtensionCredits['other'][] = array('name' => 'Piwik',
                           'version' => '0.1',
                           'author' => 'Philippe Teuwen',
//                         'url' => 'http://www.mediawiki.org/wiki/Extension:Piwik',
                           'url' => 'http://wiki.yobi.be/wiki/Piwik',
                           'description' => 'Injects Piwik JS');
$wgHooks['BeforePageDisplay'][] = 'fnPiwikHookJS';
}

?>

Then add the following to the bottom of your LocalSettings.php, customized according to what Piwik told you:

$wgPiwikURL='http://mywebsite/piwik';
$wgPiwikActionName='document.title';
$wgPiwikIdSite=1;
require_once("$IP/extensions/Piwik/Piwik.php");

Gallery2

cf http://codex.gallery2.org/Gallery2:How_To_Add_Google_Analytics_to_my_Gallery_2

Create directory /usr/share/gallery2/themes/<mytheme>/templates/local
Copy /usr/share/gallery2/themes/<mytheme>/templates/theme.tpl to /usr/share/gallery2/themes/<mytheme>/templates/local/theme.tpl, edit that copy and add just above the </body> tag the Piwik javascript

You can also clear the template cache, cf http://codex.gallery2.org/Gallery2:Editing_Templates#What_if_I_don.27t_see_my_changes