tag-manager icon indicating copy to clipboard operation
tag-manager copied to clipboard

Ability to reset custom dimension when tracking SPA with Matomo Tag Manager

Open peterbo opened this issue 4 years ago • 5 comments

For tracking with the legacy tracking code, there is _paq.push(['deleteCustomDimension', 1]); - that doesn't work with the Tag Manager. That results in custom dimensions being tracked for pageviews and actions that should not contain this data.

peterbo avatar Oct 08 '21 17:10 peterbo

@peterbo would this be fixed by https://github.com/matomo-org/tag-manager/pull/201 maybe? I think there was some discussion in https://github.com/matomo-org/tag-manager/pull/201#discussion_r343315901

Or how do you reckon would this work best?

tsteur avatar Oct 11 '21 01:10 tsteur

Hey @tsteur - https://github.com/matomo-org/tag-manager/pull/201 would definitely help to get rid of tons of workarounds. But in this case, it would not solve the problem. As an example, the following use-case:

  • An SPA, sending us an event "virtualPageView" with some variables, e.g. "topic_name", "course_name", etc.
  • These variables should be set as action custom dimensions
  • "topic_name" and "course_name" do not exist for every "virtualPageView", but on a following "virtualPageView", the variables are tracked as action custom dimensions.

Possible solutions:

  • (re)Set these variables as "null" in the datalayer, when there are no values to provide - but this would introduce some kind of "logic" to the datalayer, that increases maintenance complexity (because a full list of variables has to be present at any time and place within the CMS)
  • delete variable values before tracking a pageview - this is tricky, because when exactly is the right moment to do this?
  • At the moment, I'm getting the last "virtualPageView" event in a Tag MatomoTagManager.dataLayer.getAllEvents(); and search for all variables that have been set. The rest will be resettet to null.

Also, I'm not quite sure how to solve this the most elegant way. Perhaps a setting like "reset variable value if not present in the next event of the same type" or something like this. But this seems to be a bit too "specific". ;)

peterbo avatar Oct 11 '21 09:10 peterbo

I wonder if in that case maybe somehow needs to be hooked into this using Custom HTML tag and calling _paq.push() directly?

I would have suggested to maybe have an option to delete custom dimensions after the page view or after the event was tracked. But if I understand things correctly that wouldn't help in that case?

tsteur avatar Oct 12 '21 03:10 tsteur

I tried to execute _paq.push(['deleteCustomDimension', 1]); in a custom HTML tag, but this had no effect. Sorry, I should have explained that a bit better.

I would have suggested to maybe have an option to delete custom dimensions after the page view Mostly, variables for SPA are set with an event. (e.g. event: virtualPageview, section: test, page_type: test, business_unit: test, etc) - perhaps an option would be great to have an option for events to reset one or more variables, when it gets triggered. With this function, we could "imitate" a "real" context changing pageView. Two settings would be necessary for that

  • in an event, there could be a checkbox: "Reset certain variables on trigger"
  • in each variable there could be a checkbox: "Reset this variable if certain event gets triggered"

Or simply have one setting for an event to imitade a context changing pageView -> all variables get reset, before some get reassigned.

When this specific event gets triggered, all the selected variables get resetted, before the new variables sent with the event get assigned. I'm not sure how practical this would be, but for SPA, this certainly would help.

peterbo avatar Oct 13 '21 23:10 peterbo

Got it 👍
it almost goes into the concept of interactive vs non-interactive events or so maybe. But that's again a different story.

tsteur avatar Oct 14 '21 03:10 tsteur