I’m running a website that offers various downloadable files including .rar, .7z and .pkg formats. I want to monitor how many times these files get downloaded through Google Analytics.
Someone mentioned I could add onclick="gtag('event', 'download', {'file_name': 'document.extension'})" to my download links, but I’m confused about what exactly should go in the file_name part.
Do I just put the actual filename there? And are there any extra JavaScript libraries or tracking codes I need to include on my site to make this work properly? Any help would be appreciated!
yep, use the real filename like ‘myfile.rar’. just ensure the gtag script is loaded first - GA4 should manage it. also, check the network tab to confirm if your events are tracked right.