3 * Name: Piwik Analytics
4 * Description: Piwik Analytics Plugin for Friendika
6 * Author: Tobias Diekershoff <https://diekershoff.homeunix.net/friendika/profile/tobias>
10 /* Piwik Analytics Plugin for Friendika
12 * Author: Tobias Diekershoff
13 * tobias.diekershoff@gmx.net
15 * License: 3-clause BSD license
18 * Add the following two lines to your .htconfig.php file:
20 * $a->config['piwik']['baseurl'] = 'www.example.com/piwik/';
21 * $a->config['piwik']['siteid'] = '1';
22 * $a->config['piwik']['optout'] = true; // set to false to disable
24 * Change the siteid to the ID that the Piwik tracker for your Friendika
25 * installation has. Alter the baseurl to fit your needs, don't care
26 * about http/https but beware to put the trailing / at the end of your
29 * Documentation see http://diekershoff.homeunix.net/redmine/wiki/friendikaplugin/Piwik_Plugin
32 function piwik_install() {
33 register_hook('page_end', 'addon/piwik/piwik.php', 'piwik_analytics');
35 logger("installed piwik plugin");
38 function piwik_uninstall() {
39 unregister_hook('page_end', 'addon/piwik/piwik.php', 'piwik_analytics');
41 logger("uninstalled piwik plugin");
44 function piwik_analytics($a,&$b) {
47 * styling of every HTML block added by this plugin is done in the
48 * associated CSS file. We just have to tell Friendika to get it
49 * into the page header.
51 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/piwik/piwik.css' . '" media="all" />' . "\r\n";
54 * Get the configuration variables from the .htconfig file.
56 $baseurl = get_config('piwik','baseurl');
57 $siteid = get_config('piwik','siteid');
58 $optout = get_config('piwik','optout');
61 * Add the Piwik code for the site.
63 $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\", ".$siteid.");\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=".$siteid."\" style=\"border:0\" alt=\"\" /></p></noscript>\r\n <!-- End Piwik Tracking Tag --> </div>";
65 * If the optout variable is set to true then display the notice
66 * otherwise just include the above code into the page.
69 $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>";
73 function piwik_plugin_admin (&$a, &$o) {
74 $t = file_get_contents( dirname(__file__)."/admin.tpl");
75 $o = replace_macros( $t, array(
76 '$submit' => t('Submit'),
77 '$baseurl' => array('baseurl', t('Piwik Base URL'), get_config('piwik','baseurl' ), ''),
78 '$siteid' => array('siteid', t('Site ID'), get_config('piwik','siteid' ), ''),
79 '$optout' => array('optout', t('Show opt-out cookie link?'), get_config('piwik','optout' ), ''),
82 function piwik_plugin_admin_post (&$a) {
83 $url = ((x($_POST, 'baseurl')) ? notags(trim($_POST['baseurl'])) : '');
84 $id = ((x($_POST, 'siteid')) ? trim($_POST['siteid']) : '');
85 $optout = ((x($_POST, 'optout')) ? trim($_POST['optout']) : '');
86 set_config('piwik', 'baseurl', $url);
87 set_config('piwik', 'siteid', $id);
88 set_config('piwik', 'optout', $optout);
89 info( t('Settings updated.'). EOL);