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

Use the name of a trigger to populate an event / use it as variable

Open tsteur opened this issue 5 years ago • 7 comments

See https://forum.matomo.org/t/using-trigger-values-in-matomo-analytics-event/31092

I can see how this can be useful. At the same time not sure if it is possible to implement and how much it makes sense from the bigger picture meaning variables are used in various places not really only related to tags/triggers. We would need to look into it.

tsteur avatar Jan 04 '19 17:01 tsteur

Actually, I haven't tested but I reckon it should be doable by using eg a DataLayer Variable that reads {{ClickClasses}} and then in advanced settings set up a look up table to translate eg a class to a Modal Open etc.

We could possibly also add the name of the trigger to the dataLayer (name of trigger that was last triggered) but I'm actually not sure we expose the actual trigger name... we might be only exposing a hash... not sure

tsteur avatar Jan 04 '19 18:01 tsteur

I just double checked we only add the actual trigger name to the preview release for debugging purposes but otherwise set the name to the trigger type. It may be possible to add this variable, but need to see if there is any problem with exposing the name of the trigger/tag/... ?

tsteur avatar Jan 04 '19 20:01 tsteur

Was there any evolution to use the name of the trigger to feed events?

Indeed this would avoid redundancy in the creation of tags, and ensure the wording, in my case, of the visible elements on a page.

Clandboy avatar Feb 03 '21 14:02 Clandboy

Another suggestion (also copied-pasted in the forum), maybe it could be a good idea for a new feature to be able to capture some attribute(s) value(s). This could maybe solve this issue. eg: <span my-attibute-1="value i want to capture" my-attribute-2="something else">blabla</span>

Then it could be possible to create a trigger on CSS selector [my-attibute-1] ; configure this selector to capture my-attibute-1 and my-attibute-2 into some datalayer variables and finally create a tag fired by this trigger that will use the datalayer variable populated by the capture...

heurteph-ei avatar Apr 14 '21 08:04 heurteph-ei

+1 for being able to use the trigger name that triggered a certain tag as a variable.

@heurteph-ei - this is another issue. What you're trying to achieve is already possible (however, it is a bit complex):

  • Create a trigger (e.g. Click) with conditions "Element click" - equals CSS selector - (e.g.) span[my-attribute-1]
  • Create a variable that returns TagManager.dataLayer.get('mtm.clickElement').getAttribute('my-attribute-1');

But I agree with the idea of making this more handy - having this in a more automated manner would be great for another feature.

peterbo avatar Oct 13 '21 23:10 peterbo

This would really be a good feature. This keeps the tags clean without the need of multiple tags basically doing the same thing just with different names.

jonalange avatar Apr 28 '22 13:04 jonalange

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/use-trigger-name-as-eventname-in-tag/45743/2