I send this Variable as an Action-scoped Custom Dimension with every request in my Matomo configuration, lets say in “dimension1”.
The problem is: Once the variable has ever returned a “real” value ("SET" in the example above), then “dimension1” will never be “reset” to the empty value (neither null nor ""), even when the underlying variable returns null. It will always stay at the value "SET". There is also no possibility to define that the default value of a variable is null instead of "".
I debugged this down to the following two locations:
In plugins/TagManager/javascripts/tagmanager.js (L1233):
if ((!utils.isDefined(value) || value === null || value === false) && utils.isDefined(this.defaultValue)) {
value = this.defaultValue;
}
This sets the variable to the default value, which is the empty string "", if the variable ever returns null, undefined or false.
In plugins/TagManager/Template/Tag/MatomoTag.web.js (L232):
I think in the issue you linked to there is talk about a first fix that was implemented (“set the CD whenever there is any ‘value’, including all falsy values”, https://github.com/matomo-org/tag-manager/pull/441) and then that had to be reverted and was replaced by a different fix with “stronger” constraints (“set the CD whenever the value is set or null”, https://github.com/matomo-org/tag-manager/pull/593).
In my case, the value of the Tag Manager variable yields null, which falls back to the default value of "" (no way to prevent this in MTM), which is “falsy” (so fix #1 from the issue would have worked), but not null (so fix #2 does not work).
In the issue, the recommended workaround is to explicitly set the CD to null. But I cannot do that because my way of setting that CD is that MTM variable, which cannot in any way return null because of the mandatory default value. Any thoughts?