Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Tracker can't deal with URLs of type something?param[]=1&param[]=2 #1774

Closed
anonymous-piwik-user opened this Issue · 11 comments

2 participants

@anonymous-piwik-user

If a URL is of type something?param[]=1&param[]=2, only the last param is recorded and stored in the database (first highlighted line in the screenshot). Following patch needs to be applied to fix this (description fits on trunk-r3248, fix in second highlighted line):

* core/Tracker/Action.php
  modify function excludeQueryParametersFromUrl(), replace:
  $validQuery .= $name.'='.$value.$separator;
  with:
  if (is_array($value))
  {
    foreach ($value as $param)
    {
      $validQuery.=$name.'%5B%5D='.$param.$separator;
    }
  }
  else
  {
    $validQuery .= $name.'='.$value.$separator;
  }
@anonymous-piwik-user

addition: apparently the piwik.js is partly responsible, so in the patch above, '%5B%5D=' needs to be replaced with '[]=', also following patch needs to be applied:

* js/piwik.js
  Bugfix, related to the above.
  modify function getRequest, replace:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : locationHrefAlias) +
  with:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : unescapeWrapper(locationHrefAlias)) +
@robocoder

(In [3257]) fixes #1774 - patch by Ilinsekt; also added unit tests

@anonymous-piwik-user

Thanks, but you forgot to read my comment posted later. locationHrefAlias in piwik.js is basically window.location.href, which is partly urlencoded and is urlencoded again in getRequest(). This results in param%5B%5D being the param name in Piwik, and since core/Common.php-> getArrayFromQueryString() only checks for [], the last param overwrites all the previous. The Action.php is related, without the patch we have param=Array put in the database.

I did not notice that earlier, as the bug in piwik.js only occurs after submitting a form (otherwise it apparently uses configCustomUrl, which does not seem to be urlencoded), and I tested the patch to Action.php simply by refreshing the page.

Here's the final patch:

* core/Tracker/Action.php
  modify function excludeQueryParametersFromUrl(), replace:
  $validQuery .= $name.'='.$value.$separator;
  with:
  if (is_array($value))
  {
    foreach ($value as $param)
    {
      $validQuery.=$name.'[]='.$param.$separator;
    }
  }
  else
  {
    $validQuery .= $name.'='.$value.$separator;
  }

* js/piwik.js
  modify function getRequest, replace:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : locationHrefAlias) +
  with:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : unescapeWrapper(locationHrefAlias)) +

Sorry for the inconvenience.

@robocoder

(In [3258]) refs #1774

@anonymous-piwik-user

Seriously, it won't work without the javascript patch. I have attached some screenshots to demonstrate.

@robocoder

I'm not ignoring piwik.js ... I just haven't had time to analyze all the implications and code a fix yet.

Calling unescapeWrapper changes the semantics of some URLs which is why I haven't applied your patch.

@anonymous-piwik-user

Ah. Sorry, I misunderstood you changing the ticket to fixed without posting a reply.

@robocoder

(In [3262]) refs #1774

@anonymous-piwik-user anonymous-piwik-user added this to the Piwik 1.1 milestone
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.