MatomoConsent.hasConsent return boolean #23436
Open
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.
Description:
Currently the fallback local cookie implementation behaves differently than the tracker for the
hasConsent
. The tracker always returns a boolean and the fallback a string or boolean.This difference can also be seen in the test case, where a double bang is used to get the same results.
I would expect to behave them the same and therefore to always return a boolean for the
MatomoConsent.hasConsent
function.Before
consentCookie || consentCookie !== 0
If
consentCookie
is a string (which it is when there is one set):consentCookie
is truthy, so || short-circuits and returns the string value (e.g. "1234567890").After
!!(consentCookie && consentCookie !== 0)
If
consentCookie
is a string (e.g. "1234567890"), thereforeconsentCookie
is truthy, so && evaluates the right side consentCookie !== 0 is true. Result: true (boolean)If
consentCookie
is0
it would short-circuit again, therefore the boolean transform !! is needed.Alternative
We could also add a double bang in front of the current implementation, but I think the && is more logical than the || in this case.
Review