matomo-tracker icon indicating copy to clipboard operation
matomo-tracker copied to clipboard

Multiple Click Event listeners

Open harrygi opened this issue 5 years ago • 0 comments

Describe the bug

When you initiate the createInstance with the option as per documentation: enableLinkTracking: false, // Important!

A new link tracking event listener is created. This lead thought the React Router Switch statement to generate 2 or more event listeners for outbound clicks. One for the instantiate and another one when the the component will load.

Added the linkTracking: false, // optional, default value: true still will create the same result. The issue is the following: I see the issue be this line from the matomo-tracker (\src\MatomoTracker.ts): ` measure outbound links and downloads // // might not work accurately on SPAs because new links (dom elements) are created dynamically without a server-side page reload. this.enableLinkTracking(linkTracking)

[...] static enableLinkTracking(active: boolean) { window._paq.push(['enableLinkTracking', active]) }`

Searching on the Matomo documentation didn't find any instance of the use of the window._paq.push(['enableLinkTracking', active]) More info: Disabling Download & Outlink tracking

To Reproduce Steps to reproduce the behavior:

  1. Use the createInstance as per documentation
  2. Load another component after the initial load
  3. Run the const { enableLinkTracking } = useMatomo()
  4. Monitor that the link inside the loaded component will trigger one call but the initial components for example (header/footer links) will trigger 2!

Expected behavior Depending on the parameters will have the option to disable the link tracking on the initial load

Desktop (please complete the following information): Working with the latest version of the module: "@datapunt/matomo-tracker-react": "^0.1.5",

  • OS: [Windows]
  • Browser [ALL]

Additional context Testing a React CRA project with everything updated Adding the check to see if this is selected will resolve the issue: if(linkTracking){ this.enableLinkTracking(linkTracking); }

harrygi avatar Jun 22 '20 10:06 harrygi