sualko / cloud_piwik

Track @Nextcloud users with @matomo-org (formerly Piwik)
http://sualko.github.io/cloud_piwik/
MIT License
37 stars 18 forks source link

[Feature Request] Tracking analytics for OnlyOffice / Community Document Server views #100

Closed c-prompt closed 1 year ago

c-prompt commented 1 year ago

Edit:

I use Community Document Server 0.1.13 and ONLYOFFICE 7.8.0 and would like for Matomo to track when a user views a document (e.g., .xls, .doc, .pdf). I can see this records the page view but the page title defaults to the name of the server instead of the file name. Is there anyway to change this? Thanks.

Edit 2: From the HTML, it appears header-appname is where the proper page title is held. Perhaps this could be sent as a custom variable?

Edit 3: After playing around a bit, it appears document.title does not work consistently. Something like:

var newDocTitle = document.head.getElementsByTagName('title')[0] || document.getElementsByTagName('head')[0].getElementsByTagName('title')[0];

...in the track.js file occasionally works. But it doesn't seem to work for when .pdf documents (via the pdfviewer app) are viewed (.pdf files don't seem to be tracked at all).

sualko commented 1 year ago

If you find a fix, please open a pull request.

c-prompt commented 1 year ago

If you find a fix, please open a pull request.

Sadly, I wasn't able to and gave up. I got a bit closer playing around with this though:

      // save app name in slot 1
      _paq.push(['setCustomVariable', '1', 'App', app, 'page']);
      _paq.push(['setDownloadClasses', ["innernametext", "name", "filename", "nametext", "thumbnail-wrapper", "thumbnail", "ui-draggable", "ui-draggable-handle"]]);
   }

   if (OC && OC.currentUser && options.trackUser) {
      // set user id
      _paq.push(['setUserId', OC.currentUser]);
   }

var newDocTitle = document.head.getElementsByTagName('title')[0] || document.getElementsByTagName('head')[0].getElementsByTagName('title')[0];
var headerApp = document.getElementsByClassName('header-appname');

if (!!headerApp[0] && typeof headerApp[0].innerHTML !== null) {
    newDocTitle = headerApp[0].innerHTML.replace(/[^\x20-\x7E]+/g, '');
    }

// console.log('new= ' + JSON.stringify(newDocTitle));
// console.log('old= ' + document.title);
// console.log('1= ' + JSON.stringify(document.head.getElementsByTagName('title')[0]));
// console.log('2= ' + JSON.stringify(document.getElementsByTagName('head')[0].getElementsByTagName('title')[0]));
// console.log('3= ' + JSON.stringify(document.head.getElementsByTagName('title')[1]));
// console.log('4= ' + JSON.stringify(document.getElementsByTagName('head')[0].getElementsByTagName('title')[1]));
// console.log('5= ' + JSON.stringify(headerApp));

   if (options.trackDir === 'on' || options.trackDir === true) {
      // track file browsing

      $('#app-content').delegate('>div', 'afterChangeDirectory', function() {
         // update title and url for next page view
         _paq.push(['setDocumentTitle', newDocTitle]);
         _paq.push(['setCustomUrl', window.location.href]);
         _paq.push(['trackPageView']);
      });
   }
sualko commented 1 year ago

In that case I close the issue, because I have no time to fix it.