Make sure to always set JSON_PIWIK to native JSON when possible #15785
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Even if
JSON_PIWIK
is an object, when possible assign the native JSON method again. This way it doesn't go into theelse
shouldJSON_PIWIK
already be defined because the file was already loaded. Eg if you otherwise load JS tracker twice, the first time it would assignJSON_PIWIK = window.JSON
, the second time it would go into theelse
where it then assigns JSON manually. Seeing this on a site that I'm debugging and it appears as thenJSON_PIWIK
might be ending up somehow with the value{}
.This seems to be because that site has a method
amd
from jqueryIt is not using the loader logic
and it seems there the JSON/JSON3 value never gets assigned to
exports
:Maybe because of some incompatible
amd
or something I'm not sure how this is supposed to work. Anyway, as we're removing this in Matomo 4 anyway I don't want to spend too much time on it and rather fix this issue in that case by assigningwindow.JSON
whenever possible so it doesn't even run into that code.