Support #441
Adding a Piwik Tracking Code Into ownCloud
Description
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:
- core/templates/layout.user.php
- core/templates/layout.guest.php
- config/config.php
core/templates/layout.user.php and core/templates/layout.guest.php¶
- The ownCloud template php files needs to be modified by adding the piwik tracking code before the
</body>
tag:<!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { 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); })(); </script> <noscript><p><img src="http://piwik.examplw.com/piwik.php?idsite=9&rec=1" style="border:0;" alt="" /></p></noscript> <!-- End Piwik Code -->
config/config.php¶
- The ownCloud config php file needs to be modified by adding the following code at the end of the
$CONFIG
array:'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 *',
NOTE: The above code must be added, or else the piwik tracking code placed in the two previous files will not execute properly. I used the Firefox add-on "Ghostery" to check if the tracking code was working.
h2. Resources