Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

TrackEvents on DOM changes using a MutationObserver #160

Closed
geier1993 opened this issue May 14, 2020 · 3 comments · Fixed by #167
Closed

TrackEvents on DOM changes using a MutationObserver #160

geier1993 opened this issue May 14, 2020 · 3 comments · Fixed by #167
Labels
enhancement New feature or request

Comments

@geier1993
Copy link
Contributor

Problem:
We have a project using React and Elm. The enableLinkTracking function for React just works nice.
But for ELM (external) Javascript this doesn't work out of the Box.
Reviewing the MatomoTracker Code I just found the trackEvents() Method that is querying the DOM for data-matomo-event attributes.
However, for a reactive App we can not make use of this function as the DOM is not static.
But we like the approach to simply add a custom attribute to enable event clicking.

Solution:
To support custom attributes (data-matomo-event) on a frequently changing DOM, I think using a
MutationObserver would be a good solution dynamically add a Click-eventHandler on elements featuring a data-matomo-event attribute.

What do you think?
Are there alternatives I've missed?

@chrisvanmook
Copy link
Contributor

@geier1993 Thanks! looking good, left a review :)

@geier1993
Copy link
Contributor Author

Okay thanks! Should be fine now.

When are you publishing to npm the next time? Just have to decide tomorrow whether I just scrap everything I need or to rely on this package

@chrisvanmook
Copy link
Contributor

@geier1993 I will publish to npm tomorrow, when this is merged

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants