Tracking ownCloud user Activity

Ask all your questions regarding OC 6.x Please read the Support Forum Rules
Forum rules
ownCloud 6.x reached end of life and is officially unsupported. For details see Wiki page.

Please upgrade your ownCloud.
Jblack3285
Newbie
Posts: 2
Joined: Fri Feb 21, 2014 10:51 pm
ownCloud version: 6.0.1
Webserver: IIS
Database: MySQL
OS: Windows Server
PHP version: 5.4

Tracking ownCloud user Activity

Postby Jblack3285 » Wed Feb 26, 2014 6:06 pm

I heard piwik is a good solution to track owncloud user activity but I'm still unable to get it configured properly. So I've got piwik installed and I can see when my owncloud site has a visitor but I'm still unable to track the current user logged in. Can anyone help with that? Or does anyone know what the custom variable should be for piwik to track logged in users rather? Any further help would be much appreciated. :?: :?: :?:

nbeam85
Newbie
Posts: 7
Joined: Mon Aug 17, 2015 10:32 pm
ownCloud version: 8.0.2
Webserver: Apache
Database: MySQL
OS: Linux
PHP version: 5.5

Re: Tracking ownCloud user Activity

Postby nbeam85 » Mon Aug 17, 2015 10:50 pm

I realize this is a really old thread but I found this to be a real pain as well. I am on oc8..

The solution was to export my Piwik tracking code to a .js file and also to use java to grab the username attribute from the HTML head tag. This was hell on earth for me as I am not a java coder :). Piwik alone has been one long headache. Anyhow, I digress. Here was my solution:

owncloud installed here:
/var/www/owncloud

piwik installed in sub-folder: (so, hosted on same IP and port)
/var/www/owncloud/piwik

In the /var/www/owncloud/piwik folder create the following two files:

piwik-tracker.html
##Contains the following contents##
<script src="/piwik/tracker.js"></script>

tracker.js
##Contains the following contents##
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var useridname = document.getElementsByTagName("head")[0].getAttribute("data-user");
var u="//www.yoursiteurl.com/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['getVisitorInfo',]);
_paq.push(['setSiteId', 1]);
_paq.push(['setUserId', useridname]);
_paq.push(['getUserId']);
_paq.push(['setDownloadExtensions', 'doc|docx|zip|rar|7zip|sql|xls|xlsx|pdf']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();

-------------------

Okay, the big pain point I just solved above was getting the username. If you examine the site code after loading you will realize the username appears in the head attribute.

"var useridname = document.getElementsByTagName("head")[0].getAttribute("data-user");"

That line of code right there declares a variable named "useridname" and pulls the relevant attribute data from the head tag. Then...
_paq.push(['setUserId', useridname]);

That tells piwik to "set the user ID for the session" and to name it "the contents of the variable we just declared above"

Voila'

Now on to the rest of this....
----------------------------------------------------------

The other issue I ran into running on new browsers, and new version of apache, and new version of PHP, is that my inline Java script just plain won't execute. Apparently this is a new security thing with code.

So the answer was to create the two files I mentioned up top. If you have done so, then the last thing you need to do is add the following code:

<?php include '/var/www/owncloud/piwik/piwik-tracker.html'; ?>

after the <body> tag and before the </body> close tag in the following files:

/var/www/owncloud/core/templates/layout.user.php
/var/www/owncloud/core/templates/layout.guest.php
/var/www/owncloud/apps/files_sharing/templates/public.php

After you do all of the above, Piwik should start tracking stuff, my tracker.js code isn't cleaned up yet so there are probably some elements (the download stuff) that I haven't fixed yet but you should get basic tracking with the logged in username!

Cheers!

nbeam85
Newbie
Posts: 7
Joined: Mon Aug 17, 2015 10:32 pm
ownCloud version: 8.0.2
Webserver: Apache
Database: MySQL
OS: Linux
PHP version: 5.5

Re: Tracking ownCloud user Activity

Postby nbeam85 » Fri Aug 21, 2015 6:37 am

I decided to do a quick write-up on this as well here:
http://www.kiloroot.com/owncloud-piwik-apache-access-log-monitored-self-hosted-enterprise-file-sharing/

Hopefully that is of some use to folks trying to do monitoring!

RealRancor
ownCloud master
Posts: 17381
Joined: Sat May 26, 2012 3:00 pm
ownCloud version: 9.0.2
Webserver: nginx
Database: MySQL
OS: Linux
PHP version: 7.0.x

Re: Tracking ownCloud user Activity

Postby RealRancor » Fri Sep 11, 2015 8:20 pm

Maybe something to have a look at is this new Piwik app:

https://apps.owncloud.com/content/show. ... ent=171304
*gone*


  • Similar Topics
    Replies
    Views
    Last post

Return to “ownCloud Community Edition 6.x”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest