]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/PiwikAnalyticsPlugin.php
Piwik Analytics Plugin
[quix0rs-gnu-social.git] / plugins / PiwikAnalyticsPlugin.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Plugin to use Piwik Analytics
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Plugin to use Piwik Analytics (based on the Google Analytics plugin by Evan)
36  *
37  * This plugin will spoot out the correct JavaScript spell to invoke Piwik Analytics on a page.
38  *
39  * To use this plugin please add the following three lines to your config.php
40 #Add Piwik Analytics
41 require_once('plugins/PiwikAnalyticsPlugin.php');
42 $pa = new PiwikAnalyticsPlugin("example.com/piwik/","id");
43  *
44  * exchange example.com/piwik/ with the url (without http:// or https:// !) to your
45  *          piwik installation and make sure you don't forget the final /
46  * exchange id with the ID your laconica installation has in your Piwik analytics
47  *
48  * @category Plugin
49  * @package  Laconica
50  * @author   Tobias Diekershoff <tobias.diekershoff@gmx.net>
51  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52  * @link     http://laconi.ca/
53  *
54  * @see      Event
55  */
56
57 class PiwikAnalyticsPlugin extends Plugin
58 {
59     // the base of your Piwik installation
60     var $piwikroot = null;
61     // the Piwik Id of your laconica installation
62     var $piwikId   = null;
63
64     function __construct($root=null, $id=null)
65     {
66         $this->piwikroot = $root;
67         $this->piwikid = $id;
68         parent::__construct();
69     }
70
71     function onEndShowScripts($action)
72     {
73         $js1 = 'var pkBaseURL = (("https:" == document.location.protocol) ? "https://'.
74                 $this->piwikroot.'" : "http://'.$this->piwikroot.
75                 '"); document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\''.
76                 ' type=\'text/javascript\'%3E%3C/script%3E"));';
77         $js2 = 'piwik_action_name = ""; piwik_idsite = '.$this->piwikid.
78                '; piwik_url = pkBaseURL + "piwik.php"; piwik_log(piwik_action_name, piwik_idsite, piwik_url);';
79         $action->elementStart('script', array('type' => 'text/javascript'));
80         $action->raw($js1);
81         $action->elementEnd('script');
82         $action->elementStart('script', array('type' => 'text/javascript'));
83         $action->raw($js2);
84         $action->elementEnd('script');
85     }
86 }