hello,
i need to track some image clicks as an event for google analytics
e.g.
onclick=“ga(‘send’, ‘event’, ‘XXXX’, ‘YYYY’);”
how can i reach this?
thanks
oli
hello,
i need to track some image clicks as an event for google analytics
e.g.
onclick=“ga(‘send’, ‘event’, ‘XXXX’, ‘YYYY’);”
how can i reach this?
thanks
oli
Hi Oli,
If you are using the Image element in Cornerstone, you can add a class to the image element instead then write a Javascript code that tracks the click on the image that triggers the ga event.
Please try the following:
#1 Add a class to the image element:
For Classic Image element:

For v2 Image element:


#2 Add this code in X > Theme Options > JS:

(function($){
$( ".the_image" ).on( "click", function() {
ga('send', 'event', 'XXXX', 'YYYY');
});
})(jQuery);
The code above assumes that the class you have added to the image element is the_image.
Feel free to update the code if you used a different class.
Kindly note that since this is a custom code that changes the default behavior/display of the theme, you will be responsible to maintain or update the code in case you require further changes or if the code stops working in future updates. If you are uncertain how to proceed, it would be best to get in touch with a developer.
Hope this helps.
thanks jade! great! oli ps maybe this could be a featurerequest to have an onlick field on images…
Hi Oli,
I have added this to our Feature Request list so that it will be considered in future development.
Cheers!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.