Link with javascript for Google Analytics

Ciao.

I am using an XWiki 9.4.

Is there any way to associate a specific javascript command to a link ?

In particular, I’d wish to track how many downloads of a pdf with Google Analitycs. I have to set the javascript code to add to the link, but I don’t understand how. The code is something similar as follows:

Click here to download [[User Guide>>attach:userguide.pdf||target="_blank"]] +
onClick = “ga( ‘send’, ‘event’, ‘pdf’, ‘click’, ‘download’ );”

Any ideas ?
Thanks.

Maurizio

For the general question, see https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/SkinExtensionsTutorial/

For GA, see:

Ok for GA and how to use the GA Api within the page in order to display a chart or other. But in this case I should directly associate the js to the link because this is the right syntax for count the click of the link.