@anonymous-piwik-user opened this Issue on October 20th 2010

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 commented on October 20th 2010
@anonymous-piwik-user commented on October 22nd 2010

Attachment:
piwik_url1.png

@anonymous-piwik-user commented on October 22nd 2010

Attachment:
piwik_url2.png

@anonymous-piwik-user commented on October 20th 2010

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 commented on October 21st 2010 Contributor

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

@anonymous-piwik-user commented on October 21st 2010

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 commented on October 21st 2010 Contributor

(In [3258]) refs #1774

@anonymous-piwik-user commented on October 22nd 2010

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

@robocoder commented on October 22nd 2010 Contributor

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 commented on October 22nd 2010

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

@robocoder commented on October 22nd 2010 Contributor

(In [3262]) refs #1774

This Issue was closed on October 22nd 2010
Powered by GitHub Issue Mirror