Project

General

Profile

Support #441

Updated by Daniel Curtis over 9 years ago

Owncloud is a great web application with many feature and third-party apps. However it currently does not have any apps to integrate a piwik tracking code to obtain visitor analytics. Luckily the code can be inserted into a few files to allow piwik to work on owncloud. When a new tracking code has been created in piwik, a couple files need to be momdified: momdified and one file added: 
 # core/templates/layout.user.php core/templates/layout.base.php 
 # core/templates/layout.guest.php config/config.php 
 # config/config.php core/templates/piwik-tracking.php 

 h3. core/templates/layout.user.php and core/templates/layout.guest.php core/templates/layout.base.php 

 * The base ownCloud template php files file needs to be modified by adding the piwik tracking following code +before+ the @</body>@ tag: 
 <pre> 
 <!-- Piwik --> 
 <script type="text/javascript"> 
   var _paq = _paq || []; 
   _paq.push(['trackPageView']); 
   _paq.push(['enableLinkTracking']); 
   (function() <?php if(PIWIKTRACKING) { 
     var u=(("https:" == document.location.protocol) ? "https" : "http") + "://piwik.example.com/"; 
     _paq.push(['setTrackerUrl', u+'piwik.php']); 
     _paq.push(['setSiteId', 9]); 
     var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; 
     g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); 
   })(); get_template_part('templates/piwik-tracking'); } ?> 
 </script> 
 <noscript><p><img src="http://piwik.examplw.com/piwik.php?idsite=9&rec=1" style="border:0;" alt="" /></p></noscript> 
 <!-- End Piwik Code --> 
 </pre> 

 h3. config/config.php 

 * The ownCloud config php file needs to be modified by adding the following code at the end of the @$CONFIG@ array: file: 
 <pre> 
 'custom_csp_policy' => 'default-src \'self\'; script-src \'self\' https://piwik.example.com \'unsafe-inline\' \'unsafe-eval\'; style-src \'self\' \'unsafe-inline\'; frame-src *; img-src *; font-src \'self\' data:; media-src *', // Enables or disables the piwik tracking code ( 0 = disable / 1 = enable) 
 define(PIWIKTRACKING, 1); 
 </pre> 
 NOTE: 

 h3. core/templates/piwik-tracking.php 

 * The above code piwik-tracking.php file must be added, or else created and the piwik tracking following code placed in the two previous files will not execute properly. I used the Firefox add-on "Ghostery" added/modified to check if the tracking code was working. it: 
 <pre> 
 <!-- Piwik --> 
 <script type="text/javascript"> 
 var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.example.com/" : "http://piwik.example.com/"); 
 document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); 
 </script><script type="text/javascript"> 
 try { 
 var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2); 
 piwikTracker.trackPageView(); 
 piwikTracker.enableLinkTracking(); 
 } catch( err ) {} 
 </script><noscript><p><img src="http://piwik.example.com/piwik.php?idsite=2&rec=1" style="border:0" alt="" /></p></noscript> 
 <!-- End Piwik Tracking Code --> 
 </pre> 

 h2. Resources 

 * https://forum.owncloud.org/viewtopic.php?f=23&t=10500

Back