What if a PDF URL is referenced directly from somewhere else?

I would just like to be sure that I am understanding correctly …(and I didn’t dind a direct answer in the other posts)

Piwik tracks downloads of pdf files by tracking clicks on a link to that pdf file on a page which has the Piwik tag included … right?

So, if someone else links directly to my pdf file from another website then downloads of the pdf file from this source will not be recorded … is that correct? Is there any way around this problem?

Thanks for any information/confirmation

A direct link to your pdf file from another website will not be recorded in Piwik.

One possible solution would be to have a serverside proxy that would serve your files and use Tracking API - Analytics Platform - Matomo to record the download. You would then stop giving direct links to your pdf files and use links looking something like : http://servername/getFile.php?name=filename.

If you don’t want to use the Piwik Tracker via PHP, you could have a clientside proxy, links would still look something like : http://servername/getFile.(php|asp|…)?name=filename but instead of serving the file directly, you would output in the html the direct link to your pdf file : http://servername/filename.pdf.

If you don’t want users to find out direct links to your file and don’t want to use the PHP Piwik Tracker, you can use a mix of both methods.

Hello,

I tryed the same and found an article about here.

Can I simple copy those lines at any php-File anywhere?
I am new to PhP/Piwik so I am a little bit confused how this should work.

Best regards,

OlekBolek

Another solution is to prevent hotlinking for your PDF files. That way, people can only download them if they come from your site.

In your htaccess you can add following lines, that will return 403 Forbidden coded:


#Enables mod_rewrite, otherwise all Rewrite directives below will not work 
RewriteEngine on 
#Hotlink protection 
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$      [NC] 
RewriteCond %{HTTP_REFERER} !^http://example.com$      [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC] 
RewriteRule .*\.(pdf|zip)$ - [F,NC]

or redirect to any page:


#Enables mod_rewrite, otherwise all Rewrite directives below will not work 
RewriteEngine on 
#Hotlink protection 
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$      [NC] 
RewriteCond %{HTTP_REFERER} !^http://example.com$      [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC] 
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC] 
RewriteRule .*\.(pdf|zip)$ http://www.example.com/any_page.html [L]

http://img249.imageshack.us/img249/2806/hotlink.gif [L]

Thanks jOoL, but we have to and want to allow hotlinking … we just have to figure out a way to count it

I found this Php script that should serve the files from an unbrowsable location:

http://www.zubrag.com/scripts/download.php

So we should manage to get that working … if anyone has the precise Piwik call we should make from inside that PHP then perhaps you could post it here … Otherwise we’ll figure it out (just haven’t got around to it yet). Also if anybody who unlike me knows PHP well and confirm to me that this script has no security worries, then that would be good too

Thanks for everybody’s help