How to integrate custom JavaScript with Matomo for advanced tracking?

Hello

I am currently working on a project where I need to integrate some custom JavaScript with Matomo to track additional user interactions on my website. Specifically, I want to track certain JavaScript events that are not covered by default Matomo tracking.

Could anyone guide me on how to implement custom JavaScript tracking within Matomo or any best practices for adding extra event tracking without interfering with existing data?

Thanks

I think you can do all that with Matomo Tag Manager

Matomo Tag Manager User Guide - Matomo Analytics