-
Notifications
You must be signed in to change notification settings - Fork 58
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
TagManager (variable) values are not reset for tracking, even if they are set to "" or null. #440
Comments
@peterbo not 100% sure if I can follow. Do I get it right that the problem is happening when using the Matomo Tag? I'm thinking maybe |
@tsteur exactly! It's an out-of-the-box Matomo Configuration containing the Custom Dimensions and an out-of-the-box Matomo PageView Tag, triggered by a certain "customPageView" event that gets pushed to the dataLayer alongside the mentioned variable. The snippet you provided is spot on. This causes the exact issue that I'm seeing! |
👍 great, thanks. should be an easy fix |
Hey everyone, sorry, we'll have to reopen this issue, since the fix introduced some unexpected / unwanted behaviour that I didn't think about before. When e.g. setting Custom Dimensions from TagManager Variables (e.g. URL Parameter) for a visit scope custom Dimension (e.g. a click ID, Sub-ID or something), the dimension gets set on a page where the parameter is present, but gets reset (to empty) again on the following page, where the parameter is not present. |
@peterbo This is ought to happen with the current change. What we can do here is go back to old solution to set only for non empty values and also add an exception to set if value is set as Eg: changing https://github.com/matomo-org/tag-manager/blob/4.x-dev/Template/Tag/MatomoTag.web.js#L226 to
Will it be okay if you have to set the customDimension as null when you want to reset it ? |
Hey @AltamashShaikh - thank you for that proposal! I'll test it in the next few days, if there is any unexpected behaviour with this! |
@peterbo any update on this ? |
@AltamashShaikh sorry for the late response!! That works well for the use-cases, that I could think of (and tested it)! |
This issue has been mentioned on Matomo forums. There might be relevant details there: |
Sorry to revive this, but I think the following constellation is still a problem in this regard (as described in this forum thread as well): Suppose I have a MTM variable of type "Custom JavaScript" that can return either a non- function () { return (Math.random() > 0.5) ? "SET" : null; } Every MTM variable always has a mandatory default value mapping of When I use this variable as the value for an action-scoped Custom Dimension (mapped in the configuration variable), then the (second) fix introduced for this issue does not work: if (dimension && TagManager.utils.isObject(dimension) && dimension.index && (dimension.value || dimension.value === null)) {
tracker.setCustomDimension(dimension.index, dimension.value);
} because Also, since I only use MTM and that MTM variable is the one thing that sets my Custom Dimension, I don't have the workaround option "to set the customDimension as null when you want to reset it", as proposed in the comment above. Basically, the default value mapping for the MTM variable is the culprit here, as I can't disable that. The original fix would have worked for this situation, but I can see how that might have a couple of unintended side effects. Is there any way that I can make this work? |
@cataclyst If you set the defaultValue to |
@AltamashShaikh Hmm, yes and no. It allows the Custom Dimension to go back to the "other value", but since Matomo interprets the default value as a string ( That is especially unfortunate because my actual Custom Dimension is supposed to be blank 99.99% of the time. Now (almost) every action any visitor makes will track as some unimportant default value and clutter that report. I was thinking about that workaround before but dismissed it because it really generates a lot of noise and was hoping there would be another solution. |
@cataclyst We will discuss this issue and update you as going back to this change - https://github.com/matomo-org/tag-manager/pull/441/files seems a viable option but that will create issue for others, we might have to make this optional or a way to override it. |
@cataclyst Can you check if this PR solves the issue for you ? |
@AltamashShaikh Thank you for the possible fix. Unfortunately, that doesn't work "further down": If we return if (!isString(value)) {
value = String(value);
} and the effect is the same as before. I also tried using if (!isDefined(value)) {
value = '';
} Buuut, in that case we are coming full circle, having the empty string if (dimension && TagManager.utils.isObject(dimension) && dimension.index && (dimension.value || dimension.value === null)) {
tracker.setCustomDimension(dimension.index, dimension.value);
}
|
@cataclyst If we set the value as null here if value is "null" does it work? |
@AltamashShaikh You mean if I expanded that snippet like this? this.setCustomDimension = function (customDimensionId, value) {
customDimensionId = parseInt(customDimensionId, 10);
if (customDimensionId > 0) {
if (!isDefined(value)) {
value = '';
}
if (!isString(value)) {
value = String(value);
}
if (value === 'null') {
value = null;
}
customDimensions[customDimensionId] = value;
}
}; Unfortunately not. I would have expected this to work as well, and it sets the value at the correct index to I guess that somewhere, whatever key the value for a key is always gets converted to a string (even |
@cataclyst Thank's for checking this, for now I think having |
Thanks for the update @AltamashShaikh. I appreciate you taking this back to the team - it really seems like a tough nut to crack. Since there doesn't seem to be an easy workaround, I will discuss with my client if we should accept having the "noise" in the reports (such as a "null" row with a really high count), as long as the rest of the data is correct. |
In an SPA, I'm tracking a pageView with a configuration using a bunch of custom dimensions. (Virtual) PageViews are triggered by a custom event, that is pushed into the dataLayer with a bunch of variables.
The problem is, that after setting a variable, e.g. "section" to a value (e.g. "test") in the first dataLayer push, and in a later push, you set it to "" or null, the triggered pageView will nevertheless send "test" as a custom dimension value.
The Debugger correctly shows the variable as empty (""), but the issued requests contains the older value. It seems like the variable is not overwritten by the empty value in the tracker.
Step1: Variable is defined with "TEST1234567" and gets correctly included into the request.
Step2: Variable is defined with "" (empty string), but old value "TEST1234567" gets included into the request.
The text was updated successfully, but these errors were encountered: