]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/PiwikAnalyticsPlugin.php
8191f518112dd3092f2f3f77c0924c714dd04ff3
[quix0rs-gnu-social.git] / plugins / PiwikAnalyticsPlugin.php
1 <?php
2 /**
3  * StatusNet, 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   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Tobias Diekershoff <tobias.diekershoff@gmx.net>
26  * @copyright 2008 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * Plugin to use Piwik Analytics (based on the Google Analytics plugin by Evan)
37  *
38  * This plugin will spoot out the correct JavaScript spell to invoke
39  * Piwik Analytics on a page.
40  *
41  * To use this plugin please add the following three lines to your config.php
42  *
43  *     require_once('plugins/PiwikAnalyticsPlugin.php');
44  *     $pa = new PiwikAnalyticsPlugin("example.com/piwik/","id");
45  *
46  * exchange example.com/piwik/ with the url to your piwik installation and
47  * make sure you don't forget the final /
48  * exchange id with the ID your statusnet installation has in your Piwik analytics
49  *
50  * @category Plugin
51  * @package  StatusNet
52  * @author   Tobias Diekershoff <tobias.diekershoff@gmx.net>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://status.net/
55  *
56  * @see      Event
57  */
58
59 class PiwikAnalyticsPlugin extends Plugin
60 {
61     /** the base of your Piwik installation */
62     public $piwikroot = null;
63     /** the Piwik Id of your statusnet installation */
64     public $piwikId   = null;
65
66     /**
67      * constructor
68      *
69      * @param string $root Piwik root URL
70      * @param string $id   Piwik ID of this app
71      */
72
73     function __construct($root=null, $id=null)
74     {
75         $this->piwikroot = $root;
76         $this->piwikId   = $id;
77         parent::__construct();
78     }
79
80     /**
81      * Called when all scripts have been shown
82      *
83      * @param Action $action Current action
84      *
85      * @return boolean ignored
86      */
87
88     function onEndShowScripts($action)
89     {
90         $piwikCode = <<<ENDOFPIWIK
91
92 <!-- Piwik -->
93 <script type="text/javascript">
94 var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->piwikroot}" : "http://{$this->piwikroot}");
95 document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
96 </script>
97 <script type="text/javascript">
98 try {
99     var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$this->piwikId});
100     piwikTracker.trackPageView();
101     piwikTracker.enableLinkTracking();
102 } catch( err ) {}
103 </script>
104 <!-- End Piwik Tag -->
105
106 ENDOFPIWIK;
107
108         $action->raw($piwikCode);
109         return true;
110     }
111 }