2009-03-13 12:52:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-08-25 23:29:56 +01:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2009-03-13 12:52:01 +00:00
|
|
|
*
|
|
|
|
* Plugin to use Piwik Analytics
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Plugin
|
2009-08-25 23:29:56 +01:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-03-13 12:52:01 +00:00
|
|
|
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
|
2009-08-25 23:29:56 +01:00
|
|
|
* @copyright 2008 StatusNet, Inc.
|
2009-03-13 12:52:01 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-25 23:29:56 +01:00
|
|
|
* @link http://status.net/
|
2009-03-13 12:52:01 +00:00
|
|
|
*/
|
|
|
|
|
2009-08-25 23:42:34 +01:00
|
|
|
if (!defined('STATUSNET')) {
|
2009-03-13 12:52:01 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-20 13:06:58 +00:00
|
|
|
* Plugin to use Piwik Analytics (based on the Analytics plugin by Evan)
|
2009-03-13 12:52:01 +00:00
|
|
|
*
|
|
|
|
* This plugin will spoot out the correct JavaScript spell to invoke
|
|
|
|
* Piwik Analytics on a page.
|
|
|
|
*
|
2009-09-25 21:25:20 +01:00
|
|
|
* To use this plugin add the following to your config.php
|
2009-03-13 12:52:01 +00:00
|
|
|
*
|
2009-09-25 21:25:20 +01:00
|
|
|
* addPlugin('PiwikAnalytics', array('piwikroot' => 'example.com/piwik/',
|
|
|
|
* 'piwikId' => 'id'));
|
2009-03-13 12:52:01 +00:00
|
|
|
*
|
2009-09-25 21:25:20 +01:00
|
|
|
* Replace 'example.com/piwik/' with the URL to your Piwik installation and
|
2009-11-09 19:01:46 +00:00
|
|
|
* make sure you don't forget the final /.
|
2009-09-25 21:25:20 +01:00
|
|
|
* Replace 'id' with the ID your statusnet installation has in your Piwik
|
|
|
|
* analytics setup - for example '8'.
|
2009-03-13 12:52:01 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
class PiwikAnalyticsPlugin extends Plugin
|
|
|
|
{
|
|
|
|
/** the base of your Piwik installation */
|
2009-09-16 16:57:07 +01:00
|
|
|
public $piwikroot = null;
|
2009-08-25 23:53:24 +01:00
|
|
|
/** the Piwik Id of your statusnet installation */
|
2009-09-16 16:57:07 +01:00
|
|
|
public $piwikId = null;
|
2009-03-13 12:52:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
*
|
|
|
|
* @param string $root Piwik root URL
|
|
|
|
* @param string $id Piwik ID of this app
|
|
|
|
*/
|
|
|
|
function __construct($root=null, $id=null)
|
|
|
|
{
|
|
|
|
$this->piwikroot = $root;
|
2009-09-24 11:01:18 +01:00
|
|
|
$this->piwikId = $id;
|
2009-03-13 12:52:01 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when all scripts have been shown
|
|
|
|
*
|
|
|
|
* @param Action $action Current action
|
|
|
|
*
|
|
|
|
* @return boolean ignored
|
|
|
|
*/
|
|
|
|
function onEndShowScripts($action)
|
|
|
|
{
|
2010-12-09 01:39:04 +00:00
|
|
|
// Slight modification to the default code.
|
|
|
|
// Loading the piwik.js file from a <script> created in a document.write
|
|
|
|
// meant that the browser had no way to preload it, ensuring that its
|
|
|
|
// loading will be synchronous, blocking further page rendering.
|
|
|
|
//
|
|
|
|
// User-agents understand protocol-relative links, so instead of the
|
|
|
|
// URL produced in JS we can just give a universal one. Since it's
|
|
|
|
// sitting there in the DOM ready to go, the browser can preload the
|
|
|
|
// file for us and we're less likely to have to wait for it.
|
|
|
|
$piwikUrl = '//' . $this->piwikroot . 'piwik.js';
|
|
|
|
$piwikCode = <<<ENDOFPIWIK
|
2009-07-16 15:56:46 +01:00
|
|
|
try {
|
2010-12-09 01:39:04 +00:00
|
|
|
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->piwikroot}" : "http://{$this->piwikroot}");
|
2009-09-16 16:57:07 +01:00
|
|
|
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$this->piwikId});
|
2009-07-16 15:56:46 +01:00
|
|
|
piwikTracker.trackPageView();
|
|
|
|
piwikTracker.enableLinkTracking();
|
|
|
|
} catch( err ) {}
|
|
|
|
ENDOFPIWIK;
|
|
|
|
|
2010-12-09 01:39:04 +00:00
|
|
|
// Don't use $action->script() here; it'll try to preface the URL.
|
|
|
|
$action->element('script', array('type' => 'text/javascript', 'src' => $piwikUrl), ' ');
|
|
|
|
$action->inlineScript($piwikCode);
|
2009-03-13 12:52:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-08 01:47:23 +00:00
|
|
|
|
2015-06-06 21:04:01 +01:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-01-08 01:47:23 +00:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'PiwikAnalytics',
|
2013-11-01 12:51:41 +00:00
|
|
|
'version' => GNUSOCIAL_VERSION,
|
2010-01-08 01:47:23 +00:00
|
|
|
'author' => 'Tobias Diekershoff, Evan Prodromou',
|
|
|
|
'homepage' => 'http://status.net/wiki/Plugin:Piwik',
|
|
|
|
'rawdescription' =>
|
2011-04-29 18:22:44 +01:00
|
|
|
// TRANS: Plugin description.
|
2010-09-18 23:20:16 +01:00
|
|
|
_m('Use <a href="http://piwik.org/">Piwik</a> Open Source web analytics software.'));
|
2010-01-08 01:47:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-09-12 01:40:51 +01:00
|
|
|
}
|