How do I get the URL of the webpage on which a download occured?

I have a given PDF-URL /foo.pdf.
The link to the PDF is embedded on a webpage with the URL /bar.html; but also on other webpages.

I would like to use the API to query the number of downloads for the PDF that have taken place on the /bar.html webpage.

I have tried both the endpoint Actions.getDownload and Actions.getDownloads. However, neither endpoint gives me any information about which webpage URL the download took place on.

Is there a way to filter the API query directly to the webpage URL where the download for the PDF URL occurred? Or is there another endpoint that provides me with the desired information?

Many thanks in advance.

Hi @PaLu
I suggest you track also the download thanks to standard event tracking or content-interaction tracking…
See also:

Hi @heurteph-ei ,
Thanks for your reply. However, I’m not quite sure if I understand it correctly. The default tracking for downloads is activated. Accordingly, I get back the number of downloads of a specific resource via the API. Nevertheless, I do not receive any information in the response about the URL on which the download event took place.

However, if I understand your comment on https://github.com/matomo-org/matomo/issues/20626 correctly, this is currently not possible without further ado.

1 Like

You could use Tag Manager and Event Tracking to track the page URL of any downloads moving forward.

For example if you have an Event Tag configured as below:
image

{{PageUrl}} will show the pageURL the download is occurring on when this Event is fired.

{{ClickDestinationUrl}} will show the filename of the file that is being downloaded when the download link is clicked.

The trigger can be set based on ‘All Downloads Click’ this would then fire the tag based on the file extensions listed for this trigger.

This would trigger an event when a file is downloaded similar to below.
image

The Behaviour > Events report would then show you the PageUrl and file that was downloaded.
e.g.

1 Like

Hi @goochj03,
thank you for the proposed solution. Unfortunately we can’t use a tag manager and my job is to get the historical download numbers.

Hi @Rizwan322,
thank you for your reply. Unfortunately, it misses my question, as I want to retrieve the data from Matomo and also need the data for all downloads, not just for one that I execute manually on an ad hoc basis.

Hi @PaLu
If you can’t use the tag manager, you can add an even on download links that will do the job…
_paq.push(['trackEvent', 'Download', document.location.href, clickedElement.href]);