2009-03-13 21:52:01 +09:00
|
|
|
<?php
|
|
|
|
/**
|
2009-08-26 07:29:56 +09:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2009-03-13 21:52:01 +09: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-26 07:29:56 +09:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-03-13 21:52:01 +09:00
|
|
|
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
|
2009-08-26 07:29:56 +09:00
|
|
|
* @copyright 2008 StatusNet, Inc.
|
2009-03-13 21:52:01 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:29:56 +09:00
|
|
|
* @link http://status.net/
|
2009-03-13 21:52:01 +09:00
|
|
|
*/
|
|
|
|
|
2009-08-26 07:42:34 +09:00
|
|
|
if (!defined('STATUSNET')) {
|
2009-03-13 21:52:01 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin to use Piwik Analytics (based on the Google Analytics plugin by Evan)
|
|
|
|
*
|
|
|
|
* This plugin will spoot out the correct JavaScript spell to invoke
|
|
|
|
* Piwik Analytics on a page.
|
|
|
|
*
|
2009-09-26 05:25:20 +09:00
|
|
|
* To use this plugin add the following to your config.php
|
2009-03-13 21:52:01 +09:00
|
|
|
*
|
2009-09-26 05:25:20 +09:00
|
|
|
* addPlugin('PiwikAnalytics', array('piwikroot' => 'example.com/piwik/',
|
|
|
|
* 'piwikId' => 'id'));
|
2009-03-13 21:52:01 +09:00
|
|
|
*
|
2009-09-26 05:25:20 +09:00
|
|
|
* Replace 'example.com/piwik/' with the URL to your Piwik installation and
|
2009-11-10 04:01:46 +09:00
|
|
|
* make sure you don't forget the final /.
|
2009-09-26 05:25:20 +09:00
|
|
|
* Replace 'id' with the ID your statusnet installation has in your Piwik
|
|
|
|
* analytics setup - for example '8'.
|
2009-03-13 21:52:01 +09:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
class PiwikAnalyticsPlugin extends Plugin
|
|
|
|
{
|
|
|
|
/** the base of your Piwik installation */
|
2009-09-17 00:57:07 +09:00
|
|
|
public $piwikroot = null;
|
2009-08-26 07:53:24 +09:00
|
|
|
/** the Piwik Id of your statusnet installation */
|
2009-09-17 00:57:07 +09:00
|
|
|
public $piwikId = null;
|
2009-03-13 21:52:01 +09: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 19:01:18 +09:00
|
|
|
$this->piwikId = $id;
|
2009-03-13 21:52:01 +09:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when all scripts have been shown
|
|
|
|
*
|
|
|
|
* @param Action $action Current action
|
|
|
|
*
|
|
|
|
* @return boolean ignored
|
|
|
|
*/
|
|
|
|
function onEndShowScripts($action)
|
|
|
|
{
|
2010-12-09 10:39:04 +09: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 23:56:46 +09:00
|
|
|
try {
|
2010-12-09 10:39:04 +09:00
|
|
|
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->piwikroot}" : "http://{$this->piwikroot}");
|
2009-09-17 00:57:07 +09:00
|
|
|
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$this->piwikId});
|
2009-07-16 23:56:46 +09:00
|
|
|
piwikTracker.trackPageView();
|
|
|
|
piwikTracker.enableLinkTracking();
|
|
|
|
} catch( err ) {}
|
|
|
|
ENDOFPIWIK;
|
|
|
|
|
2010-12-09 10:39:04 +09: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 21:52:01 +09:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-08 10:47:23 +09:00
|
|
|
|
2015-06-07 05:04:01 +09:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-01-08 10:47:23 +09:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'PiwikAnalytics',
|
2013-11-01 21:51:41 +09:00
|
|
|
'version' => GNUSOCIAL_VERSION,
|
2010-01-08 10:47:23 +09:00
|
|
|
'author' => 'Tobias Diekershoff, Evan Prodromou',
|
|
|
|
'homepage' => 'http://status.net/wiki/Plugin:Piwik',
|
|
|
|
'rawdescription' =>
|
2011-04-30 02:22:44 +09:00
|
|
|
// TRANS: Plugin description.
|
2010-09-19 07:20:16 +09:00
|
|
|
_m('Use <a href="http://piwik.org/">Piwik</a> Open Source web analytics software.'));
|
2010-01-08 10:47:23 +09:00
|
|
|
return true;
|
|
|
|
}
|
2009-09-12 09:40:51 +09:00
|
|
|
}
|