Add a custom code to the controler from com_weblinks

by Lovntola   Last Updated October 04, 2019 16:10 PM - source

I wan't to add a analytics tracking code before the component com_weblinks jump to the external site with task=weblink.go.

The problem is the jump is in the controler.php. A override for this is not possible.
How can I modified / add a code to the controller to be save after the next update?

Thanks in advance

Answers 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.

October 05, 2019 13:52 PM

Related Questions

Automatic url linking

Updated December 30, 2017 17:10 PM

weblink with JCE add &task=weblink.go

Updated September 03, 2019 18:10 PM

How to add userinfo to link in Joomla Page

Updated September 18, 2019 00:10 AM

How to load a page with a System Message

Updated April 21, 2015 00:04 AM