[solved] Hide Piwik server in js

OK so you were using mod_security

Regarding the other problem, I think it is because your Alias URLs contain the host which you are forcing the click on. You can either delete your URLs from Alias URLs or wait for next version, we are discussing in: trunk Regression in forced outlink · Issue #2374 · matomo-org/matomo · GitHub

ACtually, this was a bug, so I re-packaged 1.4 - please download 1.4 final and it piwik_link will work again :slight_smile:

Hi Matt,

I upgraded to 1.4 and everything works now!

Thank you!

Okay, I got this working on one website and then I tried it on another website (different web server) and it is not working… I made sure my php.ini has

allow_url_fopen = On

and that mod_security has been whitelisted. I also checked the NET Panel on Firebug and the request to piwik.php is successful. Anything else I should check? The tracking works if I use the normal tracking code.

check error logs?

what you can do, is the following:
0) edit piwik.php on your website (the “fake” one), and comment out the line // header(…)

  1. with Firebug, look at the NET panel
  2. open in a new tab, the request done to piwik.php?..
  3. look what is displayed, there might be an error?

Hi Matt,

There are three header(…) lines in piwik.php which I edited on the website I am trying to track. I looked and there are no errors at all. Does register_globals need to be on?

Just strange since this works on another website/server.

Sorry, my mistake. I was using the wrong siteid for the new website… all the tracking was being logged on the other website’s dashboard. Sorry again.

I’ve just started testing this but have ran into a problem.

This is installed on a Wordpress blog and I can access the piwik.php but when it is accessed with parameters Wordpress is grabbing it and giving me a 404.

I am sure I need to add a rule to the .htaccess file but for the life of me I can’t get it to work.

I went through the trouble shooting steps above that’s where I found the 404 error.

Any ideas?

what’s the URL? I would expect error 500 for common errors, but 404 should mean that the URL generated is wrong, can you check it?

The first get to http://domain.com/piwik.php works fine but the second get with the parameters
http://domain.com/piwik.php?action_name=
That’s when I get the 404

That’s what makes me think it’s a .htaccess problem. 404 error is coming from the wordpress blog.

Just found a simple solution(only work if sites are on one server):
Piwik url: http://piwikhost.com/piwik/
Site1 url: http://site1.com/ (id 1)
Site2 url: http://site2.com/ (id 2)

At site1 you have to create the piwik.php with the following contents


<?
chdir('../../piwikhost.com/htdocs/piwik/'); // path to original piwik.php

require_once('piwik.php');
?>

copy orignal piwik.js and simply edit original js code to include


<!-- Piwik --> 
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://[b]site1.com[/b]/" : "http://[b]site1.com[/b]/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", [b]1[/b]);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://[b]site1.com[/b]/piwik.php?idsite=[b]1[/b]" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

The same for site 2 and others.

Finally figured out what my problem was with getting the 404 error.

I needed to have a mod_security rule for each domain where the proxy piwik is located.

Works great now and really appreciate incorporating this into Piwik.

sspy
I tried your code you posted.
got following error:
File does not exist: /var/www/html/piwik.js
interestingly in the php file I have the don’t have the link to a html directory it points to the website with the piwik files
any Idea please

[size=large]FAQ now published, see explanations in: How to - Analytics Platform - Matomo

SuperTT, I’m having the same problem you mentioned here, but I’ve change the SITE ID on the last line of the SCRIPT CALL! Everything works great if I use the code provided from the Settings - > Websites tracking code, but when I modify the PHP Proxy code in the HTML it only works for the first website.

What did you make the last line point? The Website to be tracked or the Piwik Stat Server? It seems to me you make it the website to be tracked or the whole point of a footprint would be nullified.

Also what are you referring to about the mod_security issue?

Thanks,

g

@Patchworks @bamtel @sspy @matthieu @SupraTT any idea if this method still works as last post was in 2011?

I am trying to do the same thing to hide the Matomo/Piwki server in the Javascript Tracking Code on the latest Matomo 4.15.1, I am running PHP 8.0.27.

Thank you!

Yes, the method still works :+1: Here is the step by step documentation: https://matomo.org/faq/how-to/faq_132/

2 Likes

Thanks a lot @matthieu , appreciated!