Tracking downloads is done by registering click handler callbacks for all links on a page that meet certail criteria (e.g. file extensions). (addClickListeners())
Thus the url that is tracked is not the url of the current page, it is the link-url, which is determined dynamically when the link is clicked. (logLink()) That’s why url-rewriting also needs to be done dynamically, e.g. by a rewrite function that could be registered as a hook.
I already browsed the source code but the only place I could find is setCustomRequestProcessing(). However at that stage the request is already serialized into a query string, so I’d have to split, decode, rewrite, re-encode and join the query-string, which is rather cumbersome…
It may be you found a missing feature (ability to customise download URLs?). Could you please create a bug report on: Issues · matomo-org/matomo · GitHub ? we may be able to help add this feature
As for now, matomo counts outlinks to www.ndd.ext in a different entry than outlinks to ndd.ext
I’d like to rewrite the links before they are sent to matomo, so links with and without www are counted together and btw on another site I’d like also to remove the path and query string completely and count on a domain level. And possibly without onclick.
New links to now domains are created everyday on my site so a static solution using _paq(['setDomains', ["*.hostname1.com", "hostname2.com"]]); is not fit.
I feel the said missing feature “ability to customise download urls” is very close to this “ability to customise click url”.
Is there anything new about this ?
Or how can the url be normalized before matomo uses it, and possibly without onclicks ?