Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

piwik.js: JSON stringify not working with prototype < 1.7 and mootools < 1.3 #2165

Closed
mattab opened this Issue · 5 comments

2 participants

@mattab
Owner

The bug is with custom variables and strigification.

To reproduce, this is the code:

<html><body><h1>Async code test</h1>

<script type='text/javascript' src="http://demo.magentocommerce.com/js/prototype/prototype.js" ></script>
<p>Great stuff</p>

<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
(function(){
    var u=(("https:" == document.location.protocol) ? "https://localhost/trunk/" : "http://localhost/trunk/");
    _paq.push(['setSiteId', 1]);
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setCustomVariable', '1', 'U','C']);
    _paq.push(['trackPageView']);
    var d=document,
        g=d.createElement('script'),
        s=d.getElementsByTagName('script')[0];
        g.type='text/javascript';
        g.defer=true;
        g.async=true;
        g.src=u+'js/piwik.js';
        s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code -->

The custom vars are then passed as {"1":"\"C\""}

When correct value is: {"1":["U","C"]}

This is known issue and it is working fine when using latest prototype at: https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js

The patch is:

--- js/piwik.js (revision 4048)
+++ js/piwik.js (working copy)
@@ -120,7 +120,7 @@

         if (value && typeof value === 'object' &&
                 typeof value.toJSON === 'function') {
-            value = value.toJSON(key);
+           // value = value.toJSON(key);
         }

Is it safe to apply in Piwik since we want to be compatible as much as possible, and this case Magento + old prototype represents probably a good number of users.

Is it safe to push this in , or is this code useful?

@robocoder

It allows an object to self-define how it is to be stringified. It's useful, but not a common use-case, so let's comment it out, and move on.

(Is this the source of the "No data" reports on the forum?)

@mattab
Owner

OK thanks for confirming. It is not fixing other issues than custom variable tracking

@robocoder

(In [4049]) fixes #2165 - also removed some dead code (previously commented out), and updated comments relating to the webkit bug

@robocoder

(In [4104]) refs #2165 - tested with mootools 1.2.5 (fails jslint), 1.3.1, and prototype 1.5, 1.6, and 1.7.

  • update to jslint 2011-03-13
  • tweaks to work with jslint's forin:false default
  • more aggressive cookie cleanup
@mattab
Owner

great stuff vipsoft!!

@mattab mattab added this to the Piwik 1.2.1 milestone
@robocoder robocoder was assigned by mattab
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.