@tsteur opened this issue on December 16th 2016

Some sites seem to still have problems with errors like JSON2.stringify is not a function. We already fixed some compatibility issues with prototype library etc.

I think what would make it safer is to no longer use JSON2 maybe, but instead eg JSON_PIWIK or some similar naming? This prevents the case where JSON2 is overwritten by another lib at a later point after Piwik is loaded.

Then also we could also recognize JSON 3 and prefer usage of window.json if defined.

if (typeof window.JSON==="object" && window.JSON.stringify && window.JSON.parse){
    JSON_PIWIK=window.JSON; 
} else if(typeof JSON2==="object" && JSON2.stringify && JSON2.parse) { 
  JSON_PIWIK = JSON2
} else if(typeof JSON3==="object"&&JSON3.stringify&&JSON3.parse) {
  JSON_PIWIK=JSON3;
} else {
 JSON_PIWIK = JSON2 = {... the JSON 2 version ...};
 // we could remove this part but would break some tracking features in IE7. If they still wanted to track in IE 7 and lower, we could ask sites to include JSON 2 or JSON 3 themselves
}
This issue was closed on December 16th 2016
Powered by GitHub Issue Mirror