Project

General

Profile

Support #441

Adding a Piwik Tracking Code Into ownCloud

Added by Daniel Curtis over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
-
Start date:
08/22/2014
Due date:
% Done:

100%

Estimated time:
0.20 h
Spent time:

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:
  1. core/templates/layout.user.php
  2. core/templates/layout.guest.php
  3. 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

History

#1 Updated by Daniel Curtis about 3 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 90 to 100

#2 Updated by Daniel Curtis about 3 years ago

  • Project changed from 25 to Website Hosting
  • Description updated (diff)
  • Status changed from Closed to Resolved

#3 Updated by Daniel Curtis about 3 years ago

  • Description updated (diff)
  • Status changed from Resolved to In Progress

#4 Updated by Daniel Curtis about 3 years ago

  • Description updated (diff)
  • Status changed from In Progress to Resolved

#5 Updated by Daniel Curtis about 3 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF