Execute some “code” when an external link is clicked

I’m very new to Drupal 8 and would really appreciate any advice about the best way to tackle my problem. I am creating an online video catalog that indexes videos from external vendors. All the videos are played on the vendor website after the user clicks the “play” button from my video catalog. I need some things to happen when the play button is clicked.. 1) I want to increment a counter that is a field on the node to keep track of how many times the video has been played globally. 2) I want to flag the video as watched for only that user so they can access a watched history. 3) Depending on the vendor I need to build the actual link to play the video to include the user’s id for authentication at the vendor’s website so they are redirected to the video.

I am struggling with how to accomplish all of this in Drupal 8. Do I need to write a custom module? Is there a contrib module or a combo of contrib modules that I can use?

Any advice on the best way to begin this would be very much appreciated.

Thank you!