WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
Load jQuery and comment tracking only if have comments (1 post)

  1. Todd Lahman
    Member
    Posted 2 years ago #

    Could you make jQuery loading conditional? Right now jQuery loads as a dependency when the plugin loads the Google Analytics tracking code for comments as shown below:

    <script type="text/javascript">
    
        jQuery(document).ready(function() {
    
            jQuery('#commentform').submit(function() {
    
                _gaq.push(
    
                    ['_setAccount','UA-345737-1'],
    
                    ['_trackEvent','comment','submit']
    
                );
    
            });
    
        });    
    
    </script>

    On pages that have no comments there is no need to load jQuery or the comment-reply script. I would propose using a condition that checks to see if comments are greater than zero before loading jQuery and the Google Analytics comment tracking code to decrease page load time on pages that have no comments. This is one enhancement that would help our pages load faster.

    if ( get_comments_number() > 0 )

    Thank you for a great plugin.

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic