You can use ready-made solutions:
www.google.com/analytics
www.clicktale.com
https://segment.io/
www.extrawatch.com
mouseflow.com
https://www.seevolution.com/
clicky.com
You can do amazing stuff with Google Analytics and its Event Tracker:
https://developers.google.com/analytics/devguides/...
searchenginewatch.com/article/2287906/10-Google-An...
If you're looking for a custom-made solution, you can try the following one with PHP and JavaScript:
css-tricks.com/tracking-clicks-building-a-clickmap...
Keep in mind that using third-party solutions is better performance-wise. Writing the coordinates of the mouse movements in a database in real time, needs a lot of resources.