I want to add analytics tracking code before the component com_weblinks jumps to an external site with task=weblink.go.

The problem is the jump is in the controller.php file. An override for this is not possible.

How can I modify/add code to the controller to be saved after the next update?

  • My understanding of Analytics code is that it wants to be the in the <head> of a page so that it can load and do things whilst the page is loading. If your visitor is in the weblinks.go function then they are but a few lines of code away from leaving your site. Therefore I am not really sure why you would want to try adding AT code that may never have time to do anything before the the person leaves. Javascript has a beforeunload function that can sense the user is leaving the page. Otherwise maybe try to explain what you are trying to achieve and perhaps there is another way.
    – Irata
    Oct 5, 2019 at 10:35
  • Yes, but not so easy with html-amp. What I want is add the link name to the analytics measurement protocol.
    – Lovntola
    Oct 5, 2019 at 10:38

1 Answer 1


Looking at how Weblinks works I can see that the only time weblinks.go gets involved is when you have have an option selected to count Hits for each link causing view.html.php to display this style of link:

$item->link = JRoute::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id);

at line 88 of default_items.php

I would suggest you could 'intercept' that link that is created via a plugin of your own or something like re-replacer to change the option and task values, or the whole link, to point to some piece of code that you have written that will add your link name to the analytics measurement protocol. The Plugin would probably use the onContentBefore something event to make the change.

When the end users clicks on a link they would go to your piece of code first and then you pass the processing back to weblinks and through to weblinks.go to do its bit, before it directs the end user to the linked site.

Intercepting the process via the above approach means you only have an ID and not the actual URL when you get into your code so you will need do a bit of processing to query the ID to get the related URL so you can pass that to Google.

Alternatively you could create an override category/view/tmpl/default_item.php to display the link how you want with both the id and url to pass to your code and not involve an onContentBefore plugin or re-replacer type function. And if you don't want to count Hits in weblinks you don't have to go to weblinks.go at all nor do you need the ID.

  • can I use the override for /views/weblink/tmpl/default.php to add my code? is this used befor the weblink goes to the external site? I real not understand the process from click to go out. The count of click out is added by JCE.
    – Lovntola
    Oct 7, 2019 at 20:22
  • You can use the override of default.php to replace the whole process but the code that creates the link is in /views/weblink/tmpl/default_item.php starts around line 88(J3.9.11) and then line 100 so that is the one I would override. Under the options for Com_Weblink is the field to 'Count Clicks' which causes the rendered Link to go to weblinks.go before leaving the site, JCE should not be involved. The process is either a simple Link to immediately leave the site or go via weblinks.go to count the click and then leave. You need to change either of those Links to go via a your code first.
    – Irata
    Oct 7, 2019 at 23:20
  • I don't have the file /views/weblink/tmpl/default_item.php only /views/weblink/tmpl/default.php and this has only 34 lines of code. I use com_weblink V3.7.0 from the Joomla! Project.
    – Lovntola
    Oct 8, 2019 at 11:04
  • Sorry it should be views/category/tmpl/default_items.php . That is the view where the weblinks.go is being called from.
    – Irata
    Oct 8, 2019 at 11:15
  • Thx this is what I'm looking for. My understand was this folder is for display all the links in an category on one site.
    – Lovntola
    Oct 8, 2019 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.