Quantcast
Channel: Support & Bugs - Matomo forums
Viewing all articles
Browse latest Browse all 5981

Tag Manager: Unable to reset Custom Dimension to "null" from JS variable

$
0
0

I have a “Custom JavaScript” variable in MTM with varying output over the lifetime of a visit, let’s say the following:

function () { return (Math.random() > 0.5) ? "SET" : null; }

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;
}

:arrow_up: 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):

if (dimension && TagManager.utils.isObject(dimension) && dimension.index && (dimension.value || dimension.value === null)) {
    tracker.setCustomDimension(dimension.index, dimension.value);
}

:arrow_up: This prevents the Custom Dimension from being set to that empty string "", because dimension.value is falsy.

Is there another way to set and reset Custom Dimensions via Custom JavaScript variables? And/or am I right that this is not intended behaviour?

I am on Matomo 4.15.1.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5981

Trending Articles