Track clicks on Dynamic pages

I have a client that needs to track how many times a button is clicked on a dynamic page.

For context:
The dynamic page is populated by a database that users submit information. There are 9 buttons on the dynamic page, each with a link to a part of the user’s site. My client needs to see how many times a button was clicked and be able to tell the difference between each users page.


Each dynamic page has 9 buttons. Each button has a different link. My client needs to be able to see how many times a button is clicked, and which dynamic page that was for.

For example:
Dynamic Page 1 - Button 1 had 4 Clicks
Dynamic Page 2 - Button 1 had 12 Clicks
Dynamic Page 3 - Button 1 had 2 Clicks

My current thought is to use something like this on each button (Changing what event, eventCategory, eventAction and eventLabel say):

export function downloadButton_click(event) {
  wixWindow.trackEvent("CustomEvent", {
    "event": "Document Download",
    "eventCategory": "Downloads",
    "eventAction": "Download",
    "eventLabel": $w('#dataset1').getCurrentItem().title
  } );
}

I would change what each says using data from the dataset, such as Title etc. and this should be viewable in Google Analytics.

They need to see this information historically so they can compile reports etc.

Has anyone done anything like this? Can anyone advise the best way to do this?

Thanks in advance :facepunch: