Tagged: event, GA, google analytics, onclick, search
Hi there,
How can I add a Google Analytics event to the search icon to very simply track if people click on it?
Thanks in advance,
Will
Hey willhendy,
Please add following code to functions.php file in Appearance > Editor
function av_search_ga(){
?>
<script>
jQuery(window).load(function(){
jQuery('#top #menu-item-search a').attr('onclick','YOUR CODE GOES HERE');
});
</script>
<?php
}
add_action('wp_footer', 'av_search_ga');
Best regards,
Yigit
Thanks Yigit. Does YOUR CODE refer to the Google Analytics code e.g. UA-XXXX?
Hey!
Yes, you should insert the code you would like to trigger on click in ‘YOUR CODE GOES HERE’ section :)
Cheers!
Yigit
Right. I’m afraid you’ll have to educate me… I’m not clear what code I should be triggering on click.
Hi,
Please refer to this post – https://developers.google.com/analytics/devguides/collection/analyticsjs/events
Best regards,
Yigit