Access event details in tag from "Custom Event" trigger?

My ultimate goal is to execute a custom HTML tag with data from a custom event when that event fires. If I’m going about this the wrong way, please let me know.

What I have now:

  • an event listener that pushes the event into _mtm: _mtm.push({‘event’: ‘EventName’, ‘details’: eventDetails});
  • a Custom Event trigger listening for ‘EventName’
  • a Custom HTML tag that the ‘EventName’ trigger triggers

I can see the Custom HTML tag firing, but I cannot figure out how to access anything from eventDetails in that tag.

Obviously, I can just store the event in a variable, but that’s a hack that doesn’t scale well if my event fires multiple times in quick succession. Is there a way to reference the ‘details’ object I pushed into ‘_mtm’? Or, is there some other, better way of triggering the Custom HTML tag with that data?

You can access the variables from the data layer through the Custom HTML tag see Tag Manager JavaScript API: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

This would be eg something like MatomoTagManager.dataLayer.get('details')

That works for me today: the events I’m tracking are few and far between on the page.

Is there a way I can add a feature request to get at details for “this” invocation of the tag, in case I want to track an event that comes in more frequently? I can see MatomoTagManager.dataLayer.get('details') becoming a race condition if the event fires often enough (eg., say I have images outside the viewport that are loaded when the user scrolls “close enough” to them that they’re needed and initiating a download; getting the ImageDownloadStarted event from the data layer would make it nigh impossible to determine which images were actually pulled in on a gallery page).

Well, in theory it should be the recent content even if fired multiple times within short period since JS is a single thread and the custom HTML tag would be always executed immediately and the details would be recent.

That is an excellent point which I hadn’t considered, and with which testing seems to agree. Thank you!