Pixel tracking with urlref needs url parameter?

Hello All,

using the image tracking, it seems that I need to provide the “url” parameter as soon as I add the urlref parameter.

Example: Using the default image tracking code:


<img src='http://myserver.com/piwik.php?idsite=1&rec=1' />

I get the URL information (page visited) although I didn’t add it explicitly to the image URL, but using


<img src='http://myserver.com/piwik.php?idsite=1&rec=1&urlref=http%3A%2F%2Ffoo.bar' />

tracks the referer, but not the URL (“Page URL not defined”). When I add urlref, both are logged.

Is this by intention? It makes things more complicated since I get the referrer rather simply with PHP but assembling the URL is somewhat more effort.

TIA,

Oliver

the relevant code is at: matomo/Request.php at master · matomo-org/matomo · GitHub

do you have suggestion of how to change it?

thanks for the direkt link to the relevant piece of code.

I expected $_SERVER[‘HTTP_REFERER’] to be used always if the url parameter is not passed, therefore depending only on “empty($this->params[‘url’])” but not on “empty($this->params[‘urlref’])”.

IOW I wonder why “empty($this->params[‘urlref’])” is used to decide whether to derive url from $_SERVER[‘HTTP_REFERER’].

I can’t imagine situations where the url parameter might not be passed and the URL is different from the referrer.

Of course my lack of imagination is no proof of nonexistence.

Oliver

why “empty($this->params[‘urlref’])” is used to decide whether to derive url from $_SERVER[‘HTTP_REFERER’].

$_SERVER[‘HTTP_REFERER’]. is used only when using Piwik as “default Image tracker” (where both urlref and url are not set, and we can at least set ‘url’).

yes, I know, that’s what I observed initially and what the code shows.

I just wrote what I expected as an unbiased user, and I still wonder why the page URL isn’t derived from $_SERVER[‘HTTP_REFERER’] if urlref is not empty - I don’t see the connection between url and urlref.

As I wrote initially, I can easily pass the referrer when I construct the piwik image url e.g. with php, and it would be nice it Piwik would guess the page URL if I don’t pass it.

But - as I wrote also - there might be reasons against it. IOW reasons for the code checking both url and urlref for “empty”. Maybe it is a good idea to put this reason in the existing comment in the code.

Oliver