]> git.mxchange.org Git - friendica.git/blob - addon/piwik/piwik.php
Merge branch 'omigeot-master'
[friendica.git] / addon / piwik / piwik.php
1 <?php
2
3 /*   Piwik Analytics Plugin for Friendika
4  *
5  *   Author: Tobias Diekershoff
6  *           tobias.diekershoff@gmx.net
7  *
8  *   License: 3-clause BSD license (same as Friendika)
9  *
10  *   Configuration:
11  *     Add the following two lines to your .htconfig.php file:
12  *
13  *     $a->config['piwik']['baseurl'] = 'www.example.com/piwik/';
14  *     $a->config['piwik']['sideid'] = '1';
15  *     $a->config['piwik']['optout'] = true;  // set to false to disable
16  *
17  *     Change the sideid to the ID that the Piwik tracker for your Friendika
18  *     installation has. Alter the baseurl to fit your needs, don't care
19  *     about http/https but beware to put the trailing / at the end of your
20  *     setting.
21  */
22
23 function piwik_install() {
24         register_hook('page_end', 'addon/piwik/piwik.php', 'piwik_analytics');
25
26         logger("installed piwik plugin");
27 }
28
29 function piwik_uninstall() {
30         unregister_hook('page_end', 'addon/piwik/piwik.php', 'piwik_analytics');
31
32         logger("uninstalled piwik plugin");
33 }
34
35 function piwik_analytics($a,&$b) {
36
37         /*
38          *   styling of every HTML block added by this plugin is done in the
39          *   associated CSS file. We just have to tell Friendika to get it
40          *   into the page header.
41          */
42         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/piwik/piwik.css' . '" media="all" />' . "\r\n";
43
44         /*
45          *   Get the configuration variables from the .htconfig file.
46          */
47         $baseurl = get_config('piwik','baseurl');
48         $sideod  = get_config('piwik','sideid');
49         $optout  = get_config('piwik','optout');
50
51         /*
52          *   Add the Piwik code for the side.
53          */
54         $b .= "<div id='piwik-code-block'> <!-- Piwik -->\r\n <script type=\"text/javascript\">\r\n var pkBaseURL = ((\"https:\" == document.location.protocol) ? \"https://".$baseurl."\" : \"http://".$baseurl."\");\r\n document.write(unescape(\"%3Cscript src='\" + pkBaseURL + \"piwik.js' type='text/javascript'%3E%3C/script%3E\"));\r\n </script>\r\n<script type=\"text/javascript\">\r\n try {\r\n var piwikTracker = Piwik.getTracker(pkBaseURL + \"piwik.php\", 8);\r\n piwikTracker.trackPageView();\r\n piwikTracker.enableLinkTracking();\r\n }\r\n catch( err ) {}\r\n </script>\r\n<noscript><p><img src=\"http://".$baseurl."/piwik.php?idsite=8\" style=\"border:0\" alt=\"\" /></p></noscript>\r\n <!-- End Piwik Tracking Tag --> </div>";
55         /*
56          *   If the optout variable is set to true then display the notice
57          *   otherwise just include the above code into the page.
58          */
59         if ($optout) {
60                 $b .= "<div id='piwik-optout-link'>This website is tracked using the <a href='http://www.piwik.org'>Piwik</a> analytics tool. If you do not want that your visits are logged this way you <a href='http://". $baseurl ."index.php?module=CoreAdminHome&action=optOut'>can set a cookie to prevent Piwik from tracking further visits of the site</a> (opt-out).</div>";
61         }
62
63 }
64