Event Tracking inside WebComponents / ShadowDOM


Following the sample on

I successfully could implement event tracking using data attributes.

Unfortunately the “All Elements Click” Trigger does not work on Click Events on elements inside a shadowDOM (that is typically the case when composing a page based on web components)


<div id="shadowHost"></div>

  var shadow = document.querySelector('#shadowHost').attachShadow({ mode: "open" });
    shadow.innerHTML = '<a href="#" class="primary-button" matomo-track="true" matomo-category="button" matomo-action="click" matomo-name="order now">Click inside shadowDOM</a>';

Has anyone an idea how to make it work on the shadowDOM?
Maybe somehow its. possible to add the shadowRoots to the observable elements via some Matomo JS API?

Any hints are greatly appreciated!


Created a possible fix as pull request: https://github.com/matomo-org/tag-manager/pull/544

1 Like