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

Custom Variables are not shown properly on the Piwik application #2782

Closed
anonymous-matomo-user opened this issue Nov 14, 2011 · 6 comments
Closed
Labels
Bug For errors / faults / flaws / inconsistencies etc. worksforme The issue cannot be reproduced and things work as intended.

Comments

@anonymous-matomo-user
Copy link

Hello, I found a bug in the Piwik 1.6 regarding the custom variables which are sent via Piwik Java Tracker (org.piwik.SimplePiwikTracker.java, namely).

Even if I send tracking requests with more than 1 custom variables, Piwik application shows just only one custom variable.

I checked the source-code briefly, and it seems to be a bug in the following point.

-class : "Piwik_Tracker_Visit" (file:%PIWIK_HOME%/core/Tracker/Visit.php)
-method : getCustomVariables (line:1028)

Here is the snippet which seems to be wrong(from line:1049).

foreach($customVar as $id => $keyValue)
        {
            $id = (int)$id;
            if($id < 1
                || $id > Piwik_Tracker::MAX_CUSTOM_VARIABLES
                || count($keyValue) != 2
                || (!is_string($keyValue[0]) && !is_numeric($keyValue[0]))
            )
            {
                printDebug("Invalid custom variables detected (id=$id)");
                continue;
            }
            if(empty($keyValue[1]))
            {
                $keyValue[1] = "";
            }
            // We keep in the URL when Custom Variable have empty names
            // and values, as it means they can be deleted server side

            $key = self::truncateCustomVariable($keyValue[0]);
            $value = self::truncateCustomVariable($keyValue[1]);
            $customVariables['custom_var_k'.$id] = $key;
            $customVariables['custom_var_v'.$id] = $value;
        }


Here, we fetch custom variables with the index which starts with 0.
Also this index is stored on the variable "$id"

For example)

$customVar[0] : CUSTOM_VAR_1->A
$customVar[1] : CUSTOM_VAR_2->B

Looping should be following.

(1) first fetch -> $id:0 , $keyValue -> "CUSTOM_VAR_1->A"
(2) second fetch -> $id:1 , $keyValue -> "CUSTOM_VAR_2->B"

Continuously the "if" statement checks whether$id is smaller than 1or not.
If yes, this custom variable will be ignored by "continue" statement.
But the first custom variable is pointed by $id=0 because the index starts with 0.

As a result..
When only one custom variable is defined - no custom variable will be shown.
When more than one custom variables are defined - the first custom variable always drops out.

I could make sure by printing out $customVar.
$customVar :

array(2) {
  [0]=>
  array(2) {
    [0]=>
    string(9) "Modelname"
    [1]=>
    string(19) "BROWSER Firefox 7.0"
  }
  [1]=>
  array(2) {
    [0]=>
    string(15) "Prefered Markup"
    [1]=>
    string(4) "html"
  }
}

In my case, the first one "Modelname" isn't shown always.

So I tried to correct the logic, as an example.

        foreach($customVar as $id_tmp => $keyValue)
        {
            $id = ((int)$id_tmp) + 1;
            if($id < 1
                || $id > Piwik_Tracker::MAX_CUSTOM_VARIABLES
                || count($keyValue) != 2
                || (!is_string($keyValue[0]) && !is_numeric($keyValue[0]))
            )
            {
                printDebug("Invalid custom variables detected (id=$id)");
                continue;
            }
            if(empty($keyValue[1]))
            {
                $keyValue[1] = "";
            }
            // We keep in the URL when Custom Variable have empty names
            // and values, as it means they can be deleted server side

            $key = self::truncateCustomVariable($keyValue[0]);
            $value = self::truncateCustomVariable($keyValue[1]);
            $customVariables['custom_var_k'.$id] = $key;
            $customVariables['custom_var_v'.$id] = $value;
        }

I did it by "+1" to $id in order that $id doen't have 0.

As I am not so familiar withphp as well as Piwik application, it would be helpful if you can give other good solutions.

But I would like to fix in order to show all custom variables which recieved from PiwikTracker.

Thanks a lot for your work and help :)

Rie

Keywords: Custom Variablies

@mattab
Copy link
Member

mattab commented Nov 22, 2011

tracking several custom variables works for me. Are you really using the JAVA tracker from #2172 or are you using the JAVASCRIPT tracker?

@anonymous-matomo-user
Copy link
Author

We are using the JAVA tracker API from :
http://dev.piwik.org/trac/browser/tags/1.6/libs/PiwikTracker/java

Why are you asking for?

@mattab
Copy link
Member

mattab commented Nov 28, 2011

rie, if you have found a bug in the JAVA tracker, please submit a patch to it (or the bug report) in the JAVA tracker ticket at: #2172 -- Thanks!

@anonymous-matomo-user
Copy link
Author

Hi, can you check again what I wrote ? I mean this bug is not for Java Tracker, but PHP.

We need to fix folloging php class & method.

-class : "Piwik_Tracker_Visit" (file:%PIWIK_HOME%/core/Tracker/Visit.php)
-method : getCustomVariables (line:1028)

Thanks a lot for your help!

@mattab
Copy link
Member

mattab commented Dec 1, 2011

Please submit a javascript code to replicate the issue you describe, along with the expected output / actual output

@anonymous-matomo-user
Copy link
Author

Hi Matt,

thanks a lot for your help.
I test with java-script tracker, and it worked fine with more than onecustom variable.
So we made sure that this problem comes from Java tracker.
I post the issue to the #2172 .

Thanks a lot!

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. worksforme The issue cannot be reproduced and things work as intended.
Projects
None yet
Development

No branches or pull requests

2 participants