Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
anonymous-matomo-user opened this issue Oct 20, 2010 · 11 comments
Closed
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@anonymous-matomo-user
Copy link

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-matomo-user
Copy link
Author

Attachment:
piwik_tracker_bug.png

@anonymous-matomo-user
Copy link
Author

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
Copy link
Contributor

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

@anonymous-matomo-user
Copy link
Author

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
Copy link
Contributor

(In [3258]) refs #1774

@anonymous-matomo-user
Copy link
Author

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

@anonymous-matomo-user
Copy link
Author

Attachment:
piwik_url1.png

@anonymous-matomo-user
Copy link
Author

Attachment:
piwik_url2.png

@robocoder
Copy link
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-matomo-user
Copy link
Author

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

@robocoder
Copy link
Contributor

(In [3262]) refs #1774

@anonymous-matomo-user anonymous-matomo-user added this to the Piwik 1.1 milestone Jul 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

No branches or pull requests

2 participants