How can I track PDF downloads?

I set up a page for a client that posts a lot of research in PDFs. I’d like to set up Google Analytics to track the number of downloads for each PDF. I followed the instructions on this video to the letter. I add a button, it works fine. I add the code to track clicks on the button. Then, when I click the button on the live site, it shows up in Realtime analytics, but it doesn’t actually trigger a download. I notice others have had this problem here:
https://www.wix.com/corvid/forum/community-discussion/is-there-a-way-to-get-a-number-on-downloads
but I couldn’t find a resolution. Here’s the code I added:

import wixWindow from ‘wix-window’ ;
export function mybutton_click(event) {
wixWindow.trackEvent( “CustomEvent” , {
event: “Funnel” ,
eventCategory: “PDFdownload” ,
eventAction: “Downloads” ,
eventLabel: event.target.label,
})
}
Any ideas what I’m doing wrong? Also if this works, may I ask if Google Analytics will track events for longer periods of time? Realtime will keep a running 30 minute count, but could I use this to find out all-time number of downloads? Thanks!

Any luck solving this? I’m having the same problem.

In the end, I never solved the problem. I just set up tag manager to track clicks on specific words (the titles of research products, in this client’s case). This was an effective workaround, but with major drawbacks. E.g., every location across the site where I want people to be able to download the doc has to either have the same exact wording, or the trigger has to be configured to fire on every variation in the wording. Also, the wording has to be unique. So, I can’t, say, have the title and then a “Download PDF” link off to the side. If I did, I could track every time someone clicks “Download PDF”, but if that appears in 100’s of places on the site, I wouldn’t actually know which docs were generating traffic. In the end it’s a flawed but sufficient solution.