Hello there :D
I am using Google Analytics in order to track my page traffic. I want to track my outbound links as well. Which works if I add the “onclick” attribute to my links. However, I have not found a way to add this attribute to the destination URL of the Image Widget.
I am using the Image Widget in order to display ads. So the destination URL leads the User to the homepage of the advertisor. I want however, to also track how many people are clicking on the image.
Here is the google analytics thread about how to track outbound links:
https://support.google.com/analytics/answer/1136920?hl=en
Is it possible to use that tool for the Image Widget as well? If so, how do I manage to add those attributes to the destination URL?
Thanks for your help!
Hello there. I was investigating and found out that it is possible to extend existing widgets from SiteOrigin. See https://siteorigin.com/docs/widgets-bundle/getting-started/extending-existing-widgets/.
I tried to adjust the image widget so that I could add the “onlick variable” to the URL. This is what I came up with:
I copied the subfolder “image” in /plugins/so-widgets-bundle/widgets and renamed it to “werbung”. Then I opened image.php, renamed it to werbung.php and made no changes to the code, except renaming it in the first few lines.
Afterwards, I opened /tpl/default.php and made the following changes (on line 46):
[/code]
function mytheme_extend_button_form( $form_options, $widget ){
// Lets add a new theme option
if( !empty($form_options[‘design’][‘fields’][‘theme’][‘options’]) ) {
$form_options[‘design’][‘fields’][‘theme’][‘options’][‘test’] = __(‘Test Style’, ‘mytheme’);
}
return $form_options;
}
add_filter(‘siteorigin_widgets_form_options_sow-button’, ‘mytheme_extend_button_form’, 10, 2);
I did not know where to put it as it was only described for the button widget, and I could not really figure out how to do it with the image widget. Thanks for your help!
Sorry for the complete crap usage of the code variable up there :D I try it again here:
Changes to tpl/default.php on line 46:
And the one I left out:
Thanks
Hi Nico,
I’m very sorry for the missing this.
To clarify, as you’ve suspected; This isn’t possible by default – I’ll log it as a feature request.
I would strongly recommend using JavaScript (specifically jQuery) instead of creating a custom widget as based on your code you don’t really need to do anything fancy with it.
Regardless, I would not recommend editing a core plugin files as any changes will be lost on update. Instead, make a custom plugin as it’ll only take you a few minutes and it’ll prevent a headache down the line. Could you send me the full plugin files so I can see what you’ve done completely without having to copy code (and thus potentially create further issues). Please upload the export to a 3rd party file hosting site such as teknik.io.
This is a private message.
Hi Nico,
Oddly, I was able to use that version without it erroring. You should try enabling WP_DEBUG so that you can get a better idea of what is causing this issue.
Hello. That is odd. I figured out where the problem was with the help of wp debug. It was because I forgot to rename the Widget properly in werbung.php, as it looks like. Thanks for your help anyway and I would love to see this feature in future updates!