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

Make JSON usage in piwik.js a bit more stable and reduce conflict with other libraries #11023

Closed
tsteur opened this issue Dec 16, 2016 · 0 comments · Fixed by #11024
Closed
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@tsteur
Copy link
Member

tsteur commented Dec 16, 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
}
@tsteur tsteur added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Dec 16, 2016
mattab pushed a commit that referenced this issue Dec 16, 2016
* refs #11023 better piwik.js json compatibility

* fix some tests

* fix json lint tests
mattab added a commit that referenced this issue Dec 18, 2016
* refs #11023 better piwik.js json compatibility

* fix some tests

* fix json lint tests

* Display titles correctly in API reference doc

* Slightly better code
mattab added a commit that referenced this issue Dec 19, 2016
#11035)

* refs #11023 better piwik.js json compatibility

* fix some tests

* fix json lint tests

* Display titles correctly in API reference doc

* Slightly better code

* Prevent error reported in #11028

* Per Thomas feedback

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant