[Plugin: Google Analytics for WordPress] Load jQuery and comment tracking code modification request
-
On pages that have no comments there is no need to load jQuery or the comment-reply script. To make pages load faster I modified your plugin to only load the comment tracking code and jQuery when there are more than zero comments. I have provided the code below, and was hoping you could add this to the plugin.
In the googleanalytics.php file from line 1449 to line 1490 (after the code modification) below:
function track_comment_form_head() { if (is_singular() && get_comments_number() > 0) { global $post; $yoast_ga_options = get_option('Yoast_Google_Analytics'); if ( yoast_ga_do_tracking() && isset( $yoast_ga_options["trackcommentform"] ) && $yoast_ga_options["trackcommentform"] && ( 'open' == $post->comment_status ) ) wp_enqueue_script('jquery'); } } add_action('wp_print_scripts','track_comment_form_head'); $comment_form_id = 'commentform'; function yoast_get_comment_form_id($args) { global $comment_form_id; $comment_form_id = $args['id_form']; return $args; } add_filter('comment_form_defaults', 'yoast_get_comment_form_id',99,1); function yoast_track_comment_form() { if (get_comments_number() > 0) { global $comment_form_id, $post; $yoast_ga_options = get_option('Yoast_Google_Analytics'); if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] ) { ?> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#<?php echo $comment_form_id; ?>').submit(function() { _gaq.push( ['_setAccount','<?php echo $yoast_ga_options["uastring"]; ?>'], ['_trackEvent','comment','submit'] ); }); }); </script> <?php } } } add_action('comment_form_after','yoast_track_comment_form');http://ww.wp.xz.cn/extend/plugins/google-analytics-for-wordpress/
The topic ‘[Plugin: Google Analytics for WordPress] Load jQuery and comment tracking code modification request’ is closed to new replies.