Piwik module/plugin for MODx

von Thomas Jakobi am Montag, 9. Februar 2009 um 14:23 Uhr. Kommentare (17)

On some customer websites I use Piwik as software for web analytics. The following MODx module (version 0.6.6a) displays a few Piwik widgets in the MODx backend and the corresponding plugin inserts the suitable code for Piwik at the end of the html code generated by MODx.

The base of the module/plugin is an separate (!) installation of Piwik

First download the packed files of the module and upload them to /assets/modules/piwikx.

Then you have to create a new plugin called PiwikX and paste the following plugin code into it.

piwikx.plugin
/*
 * PiwikX simply integrates the <a href='http://www.piwik.org'>Piwik</a> statistic on your site.
 *
 * @package PiwikX
 * @subpackage modx_plugin
 * @link http://www.partout.info/piwik_modx.html
 *
 * @version 0.6.6a <17.05.2010>
 * @author Thomas Jakobi <Kontakt>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
 
/* MODx event
 OnParseDocument
 */
 
$piwikURL = (isset($piwikURL)) ? $piwikURL : '';
$piwikSiteId = (isset($piwikSiteId)) ? $piwikSiteId : 0;
 
if (!isset($modx))
    die();
 
// invoke module
$class_file = MODX_BASE_PATH.'assets/modules/piwikx/piwikx.class.php';
if (!file_exists($class_file))
    $modx->messageQuit(sprintf('Classfile "%s" not found. Did you upload the module files?', $class_file));
require_once ($class_file);
 
// MODx event handling
$e = &$modx->Event;
switch ($e->name) {
    case "OnParseDocument":
        $piwikx_lang = array();
        $PiwikX = new PiwikX($piwikURL, $piwikSiteId, $piwikx_lang);
 
		$PiwikX->piwikUsername = (isset($piwikUsername)) ? $piwikUsername : '';
		$PiwikX->piwikPassword = (isset($piwikPassword)) ? $piwikPassword : '';
		$PiwikX->piwikActionName = (isset($piwikActionName)) ? $piwikActionName : '';
		$PiwikX->piwikJsName = (isset($piwikJsName)) ? $piwikJsName : 'piwik.js';
		$PiwikX->piwikGroupTrack = (isset($piwikGroupTrack)) ? explode(',', $piwikGroupTrack) : array();
		$PiwikX->piwikGroupExclude = (isset($piwikGroupExclude)) ? explode(',', $piwikGroupExclude) : array();
		$PiwikX->piwikUserTrack = (isset($piwikUserTrack)) ? explode(',', $piwikUserTrack) : array();
		$PiwikX->piwikUserExclude = (isset($piwikUserExclude)) ? explode(',', $piwikUserExclude) : array();
 
		$includeChunk = $PiwikX->includeChunk();
		$modx->regClientHTMLBlock($includeChunk);
	break;
 
	default :
		return; // stop here - this is very important. 
	break;
}

Now you have to create a new module and paste the following module code into it.

piwikx.module
/*
 * PiwikX simply integrates the <a href='http://www.piwik.org'>Piwik</a> statistic on your site.
 *
 * @package PiwikX
 * @subpackage modx_module
 * @link http://www.partout.info/piwik_modx.html
 *
 * @version 0.6.6a <17.05.2010>
 * @author Thomas Jakobi <Kontakt>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
 
if (!isset($modx))
    die();
 
$piwikURL = (isset($piwikURL)) ? $piwikURL : '';
$piwikSiteId = (isset($piwikSiteId)) ? $piwikSiteId : 0;
 
// manager language setting
$language = $modx->config['manager_language'];
 
// individual user language setting (if set)
$query = 'SELECT setting_name, setting_value FROM '.$modx->getFullTableName('user_settings').' WHERE setting_name=\'manager_language\' AND user='.$modx->getLoginUserID();
$records = $modx->db->query($query);
if ($modx->db->getRecordCount($records) > 0) {
    $record = $modx->db->getRow($records);
    $language = $record['setting_value'];
}
 
// load classfile
$class_file = MODX_BASE_PATH.'assets/modules/piwikx/piwikx.class.php';
if (!file_exists($class_file))
    $modx->messageQuit(sprintf('Classfile "%s" not found. Did you upload the module files?', $class_file));
require_once ($class_file);
 
// load localization
$piwikx_lang = array();
include_once MODX_BASE_PATH.'assets/modules/piwikx/lang/english.inc.php';
 
if ($language != 'english') {
    $lang_file = MODX_BASE_PATH.'assets/modules/piwikx/lang/'.$language.'.inc.php';
    if (file_exists($lang_file)) {
        include_once $lang_file;
    }
}
 
// invoke module
$PiwikX = new PiwikX($piwikURL, $piwikSiteId, $piwikx_lang);
 
$PiwikX->piwikUsername = (isset($piwikUsername)) ? $piwikUsername : '';
$PiwikX->piwikPassword = (isset($piwikPassword)) ? $piwikPassword : '';
$PiwikX->piwikTokenAuth = (isset($piwikTokenAuth)) ? $piwikTokenAuth : '';
$PiwikX->piwikActionName = (isset($piwikActionName)) ? $piwikActionName : '';
$PiwikX->piwikJsName = (isset($piwikJsName)) ? $piwikJsName : 'piwik.js';
$PiwikX->piwikGroupTrack = (isset($piwikGroupTrack)) ? explode(',', $piwikGroupTrack) : array();
$PiwikX->piwikGroupExclude = (isset($piwikGroupExclude)) ? explode(',', $piwikGroupExclude) : array();
$PiwikX->piwikUserTrack = (isset($piwikUserTrack)) ? explode(',', $piwikUserTrack) : array();
$PiwikX->piwikUserExclude = (isset($piwikUserExclude)) ? explode(',', $piwikUserExclude) : array();
echo $PiwikX->displayModule();
return;
 

Module configuration

The module can be called now after reloading the MODx manager. Since the module is not yet configured, a summary page with the minimal and the complete configuration will be displayed. One of these configurations must be inserted in the module configuration and the settings have to filled according to the corresponding Piwik installation. As an example the minimal configuration is shown here:

&piwikURL=URL to your Piwik installation;text;http://your.piwik.installation
&piwikSiteId=Piwik Site ID;text;1
&piwikUsername=Username to display the Piwik widgets;text;
&piwikPassword=md5 encrypted password to display the Piwik widgets;text;

Screenshot des Piwik Moduls piwikURL contains the url of the Piwik installation.

piwikSiteId contains the id of the website inside of piwik (Piwik -> Admin settings -> Sites).

piwikUsername contains the name of a new user inside of piwik (Piwik -> Admin settings -> Users). This user has to have viewing acces for the website to track. Caution: This user cannot be the piwik super user.

piwikPassword is the md5 encrypted password of this user (Piwik -> Admin settings -> Users).

piwikActionName contains the name of a template variable. The content of this variable will be parsed (contained snippet calls will be executed and document or template variables will be replaced – snippets have to be called cached und template variables should be called as in page templates ) and used as tracking title for Piwik. If this option is not set, the pagetitle will be used as tracking title.

piwikUserExclude and piwikGroupExclude could contain a comma-separated list of user names and/or web groups. These users and/or groups will be excluded from piwik tracking if they are logged into the MODx frontend or backend.

After that you have to enable parameter sharing in the module configuration and add the PiwikX plugin in the dependencies of the module.

Widgets in the backend

The module should display now a few Piwik widgets in the MODx backend. The configuration of these widgets could be set in the file <language>.managerwidgets.php – a small howto for modifications in this file is written in the german documentation.

Plugin configuration

Now you have to select PiwikX in import module shared parameters of the PiwikX plugin configuration and activate OnParseDocument as system event for the plugin. After saving the plugin the Piwik code will be inserted at the end of the html code generated by MODx. Since this code is enclosed in a DIV with the class piwik, it could be hidden by  .piwik { display: none } in the CSS file.


Speichern auf digg Speichern auf slashdot Speichern auf del.icio.us Speichern auf technorati Speichern auf furl Speichern auf Google Speichern auf Mister Wong
Kommentare 1 bis 10 von 17 | Nächste | Letzte
Nike Air Max
air max nike
am 13. September. 2013, 12:33:19 Uhr
Some men declare that exercising makes their particular penises even bigger people state that they鈥檝e got tried many exercises and do not been able to create an inch associated with measurement upon their own male organs. On this page I鈥檓 going to show you just what physical exercise really does in relation to penile progress as well as whether or not it does not take best method involving including inches wide on the dimensions of the penis鈥?
iSamLu
pokerstars scam - pokerstars cheaters
am 29. August. 2013, 16:11:13 Uhr
Rigged, bullshit, a joke, cheating.. Wonderful! BTW, this is not just Pokerstars but also this affects Full Tilt and whatever poker, same shit.
pokerstars is not random - it's a scam, rigged and unfair to players! DO NOT EVER PLAY THERE! AND JOIN US TO FIGHT THEM!
blqs
Re: Piwik module/plugin for MODx
am 3. Juli. 2012, 16:10:30 Uhr
This plugin for ModX Evolution or Revolution version?
elz64
and what about Revo ?
am 18. Januar. 2012, 21:14:14 Uhr
Hi,

I used your plugin one time in an Evo site but wonder if you'll port it to Revolution ?

thank you
Thomas Jakobi
Re: MODx Revolution
am 11. Juni. 2011, 13:42:45 Uhr
Not in the pipeline yet.
MODx Revolution
am 12. April. 2011, 03:44:08 Uhr
Hi,

Are there any plans to extend this plugin for MODx Revolution? Would be great to have the same functionality in Revo as in Evo.
Thomas Jakobi
Re: The Super User cannot be authenticated using the 'logme' mechanism.
am 7. Juni. 2010, 21:02:00 Uhr
piwikUsername contains the name of a new user inside of piwik (Piwik -> Admin settings -> Users). This user cannot be the piwik super user.
Chris Rabkin
The Super User cannot be authenticated using the 'logme' mechanism.
am 7. Juni. 2010, 19:16:27 Uhr
I have gone over my installation several times but continue to receive this message when I try to run the module.

Any suggestions? I think it my have something to do with the actual piwik config file but i cannot find accurate documentation to change it.
thanks
Chris rabkin
Thomas Jakobi
Re: Uncaught ReferenceError: piwikTracker is not defined
am 18. Mai. 2010, 14:24:14 Uhr
Fixed in 0.6.6a
DiegoBM
Uncaught ReferenceError: piwikTracker is not defined
am 17. Mai. 2010, 13:46:59 Uhr
The new javascript code doesn't work.
The error says:

"Uncaught ReferenceError: piwikTracker is not defined"

in the line:

piwikTracker.enableLinkTracking();
Kommentare 1 bis 10 von 17 | Nächste | Letzte