rewrite/normalize urls while tracking


(Leo B) #1

Hi!

On my website, downloads are identified by numeric ids that are part of the url. Any subsequent filenames are ignored and lead to the same content.

E.g.

http://mysite.com/1/2/leo.pdf
http://mysite.com/1/2/dummy.pdf
http://mysite.com/1/2

… all yield the same file, because the id that identifies the file is “1/2”.

Thus when tracking downloads with Matomo I’d like to reduce the urls to the relevant parts and chop any trailing text.

Is there a hook for “normalizing/rewriting” urls in the javascript tracking client?
Or is there an easy way to do it on the server side?

Cheers,
–leo


(Lukas Winkler) #2

Hi,

setCustomUrl seems like exactly what you want

 _paq.push(['setCustomUrl', "/test"]);

(Leo B) #3

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… :frowning: